def get_incremental_task(project_id, user_id=None, user_ip=None,
external_uid=None, offset=0, limit=1, orderby='id', desc=False):
"""Get a new task for a given project with its last given answer.
It is an important strategy when dealing with large tasks, as
transcriptions.
"""
candidate_tasks = get_candidate_task_ids(project_id, user_id, user_ip,
external_uid, limit, offset,
orderby='priority_0', desc=True)
total_remaining = len(candidate_tasks)
if total_remaining == 0:
return None
rand = random.randrange(0, total_remaining)
task = candidate_tasks[rand]
# Find last answer for the task
q = session.query(TaskRun)\
.filter(TaskRun.task_id == task.id)\
.order_by(TaskRun.finish_time.desc())
last_task_run = q.first()
if last_task_run:
task.info['last_answer'] = last_task_run.info
# TODO: As discussed in GitHub #53
# it is necessary to create a lock in the task!
return [task]
评论列表
文章目录