Support sorting by task active duration

This commit is contained in:
allegroai 2021-01-05 17:44:17 +02:00
parent 0ef018c931
commit b89de43373
3 changed files with 15 additions and 6 deletions

View File

@ -327,11 +327,14 @@ class TaskBLL(object):
@staticmethod
def set_last_update(
task_ids: Collection[str], company_id: str, last_update: datetime
task_ids: Collection[str], company_id: str, last_update: datetime, **extra_updates
):
return Task.objects(id__in=task_ids, company=company_id).update(
upsert=False, last_update=last_update
)
tasks = Task.objects(id__in=task_ids, company=company_id).only("status", "started")
for task in tasks:
updates = extra_updates
if task.status == TaskStatus.in_progress and task.started:
updates = {"active_duration": (datetime.utcnow() - task.started).total_seconds(), **extra_updates}
Task.objects(id=task.id, company=company_id).update(upsert=False, last_update=last_update, **updates)
@staticmethod
def update_statistics(
@ -394,8 +397,8 @@ class TaskBLL(object):
}
extra_updates["metric_stats"] = metric_stats
Task.objects(id=task_id, company=company_id).update(
upsert=False, last_update=last_update, **extra_updates
TaskBLL.set_last_update(
task_ids=[task_id], company_id=company_id, last_update=last_update, **extra_updates
)
@classmethod

View File

@ -150,6 +150,7 @@ class Task(AttributedDocument):
"created",
"started",
"completed",
"active_duration",
"parent",
"project",
("company", "name"),
@ -203,6 +204,7 @@ class Task(AttributedDocument):
started = DateTimeField()
completed = DateTimeField()
published = DateTimeField()
active_duration = IntField(default=0)
parent = StringField()
project = StringField(reference_field=Project, user_set_allowed=True)
output: Output = EmbeddedDocumentField(Output, default=Output)

View File

@ -434,6 +434,10 @@ _definitions {
type: string
format: "date-time"
}
active_duration {
description: "Task duration time (seconds)"
type: integer
}
parent {
description: "Parent task id"
type: string