Fix task and model last_change handling

Improve db model index
Improve db model infrastructure
This commit is contained in:
allegroai
2021-01-05 18:17:29 +02:00
parent 29c792d459
commit 59994ccf9c
14 changed files with 80 additions and 35 deletions

View File

@@ -43,6 +43,7 @@ class ChangeStatusRequest(object):
status_message=self.status_message,
status_changed=now,
last_update=now,
last_change=now,
)
if self.new_status == TaskStatus.queued:
@@ -194,3 +195,11 @@ def get_task_for_update(
expected=TaskStatus.created, status=task.status
)
return task
def update_task(task: Task, update_cmds: dict, set_last_update: bool = True):
now = datetime.utcnow()
last_updates = dict(last_change=now)
if set_last_update:
last_updates.update(last_update=now)
return task.update(**update_cmds, **last_updates)