'Store return value and state of an executed task.'

@retry
def _store_result(self, task_id, result, state, traceback=None, max_retries=3, **kwargs):

    session = self.ResultSession()
    with session_cleanup(session):
        task = list(session.query(Task).filter((Task.task_id == task_id)))
        task = (task and task[0])
        if (not task):
            task = Task(task_id)
            session.add(task)
            session.flush()
        task.result = result
        task.status = state
        task.traceback = traceback
        session.commit()
        return result
