Endpoint to start a new worker activity
https://redmine.teklia.com/issues/11528
A new StartWorkerActivity endpoint, at POST /process/start-activity/, exclusively requires Ponos task authentication. It will allow a task to ask for the next queued WorkerActivity to be marked as started, and returns the element associated with that activity.
This allows tasks to use WorkerActivities as a replacement for the elements.json files, and allows chunks that may be processing elements at different speeds to process different amounts of elements. Faster chunks could pick up the slack for slower chunks, which speeds up the process overall.
This endpoint takes no request body and has no ID in its path, since all it needs is found in the authenticated task. It must return an HTTP 400 if:
- the task has no WorkerRun set;
- the task is in a final state, thus not supposed to process anything;
- the
activity_stateon the process is notready.
Then, in a transaction, the endpoint must:
- find the next
queuedWorkerActivity that matches the WorkerRun's attributes; -
lock it using
SELECT … FOR NO KEY UPDATE; - use
SKIP LOCKEDto ignore any activity that was already locked; - if no activity is found, return HTTP 404;
- if one is found, set the activity's state to
startedand update itsstarteddate; - return the element for this activity using the
ProcessElementSerializer, just likeListProcessElementswithwith_image=True.