def _get_task_meta_for(self, task_id):
     """Get task metadata for a task by id."""
     session = Session()
     try:
         task = None
         for task in session.query(Task).filter(Task.task_id == task_id):
             break
         if not task:
             task = Task(task_id)
             session.add(task)
             session.commit()
         if task:
             return task.to_dict()
     finally:
         session.close()
 def _store_result(self, task_id, result, status, traceback=None):
     """Store return value and statu of an executed task."""
     session = Session()
     try:
         tasks = session.query(Task).filter(Task.task_id == task_id).all()
         if not tasks:
             task = Task(task_id)
             session.add(task)
         else:
             task = tasks[0]
         task.result = result
         task.status = status
         task.traceback = traceback
         if task.status == states.STARTED:
             task.date_began = datetime.now()
         session.commit()
     finally:
         session.close()
     return result