Track task execution time
https://redmine.teklia.com/issues/8785
To limit task execution time, we need to know how long a task has been running for.
Task.started
and Task.finished
are two new nullable DateTimeField
. Both fields are visible, but read-only, in the Django admin.
Two database constraints should require that started >= created
when started
is not null, and finished >= started
when finished
is not null, just like on Process
.
RetrieveTask
should include both fields in its API response. RetrieveProcess
should also include both fields in the tasks
of the process.
UpdateTask
and PartialUpdateTask
should, when a task's state is updated to Running
, set Task.started
to the current time. When a task's state is updated to any final state, Task.finished
is set to the current time, unless Task.started
is None
since the constraints will block that.
The run_docker_task
RQ task should set Task.started
as soon as the Docker container is started. Both run_docker_task
and run_task_rq
should set Task.finished
when reaching any final state, if Task.started
is not None
.