Skip to content

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_state on the process is not ready.

Then, in a transaction, the endpoint must:

  1. find the next queued WorkerActivity that matches the WorkerRun's attributes;
  2. lock it using SELECT … FOR NO KEY UPDATE;
  3. use SKIP LOCKED to ignore any activity that was already locked;
  4. if no activity is found, return HTTP 404;
  5. if one is found, set the activity's state to started and update its started date;
  6. return the element for this activity using the ProcessElementSerializer, just like ListProcessElements with with_image=True.