Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This introduces several changes to the way `servicelayer` exposes a RabbitMQ-based implementation for Aleph tasks. ### Objects **Task** A data class that contains information about one Aleph task. Also contains methods to track how many times the task was retried. ``` task_id: str job_id: str delivery_tag: str operation: str context: dict payload: dict priority: int collection_id: Optional[str] = None ``` **Dataset** Object which keeps track of the status of currently running tasks by populating Redis. One `Dataset` instance corresponds to one `collection_id`. This is also the object which the `/status/` API ends up querying to populate its response. Redis keys used by the `Dataset` object: - `tq:qdatasets`: set of all `collection_id`s of active datasets (a dataset is considered active when it has either running or pending tasks) - `tq:qdj:<dataset>:taskretry:<task_id>`: the number of times `task_id` was retried All of the following keys refer to `task_id`s or statistics about tasks per a certain dataset (`collection_id`): - `tq:qdj:<dataset>:finished`: number of tasks that have been marked as "Done" and for which an acknowledgement is also sent by the Worker over RabbitMQ. - `tq:qdj:<dataset>:running`: set of all `task_id`s of tasks currently running. A "Running" task is a task which has been checked out, and is being processed by a worker. - `tq:qdj:<dataset>:pending`: set of all `task_id`s of tasks currently pending. A "Pending" task has been added to a RabbitMQ queue (via a `basic_publish` call) by a producer (an API call, a UI action etc.). - `tq:qdj:<dataset>:start`: the UTC timestamp when **either** the first `task_id` has been added to a RabbitMQ queue (so, we have our first Pending task) or the timestamp when the first `task_id` has been checked out (so, we have our first Running task). The `start` key is updated when the first task is handed to a Worker. - `tq:qdj:<dataset>:last_update`: the UTC timestamp from the latest change to the state of tasks running for a certain `collection_id`. This is set when: a new task is Pending, a new task is Running, a new task is Done, a new task is canceled. - `tq:qds:<dataset>:<stage>`: a set of all `task_id`s that are either running or pending, for a certain stage. - `tq:qds:<dataset>:<stage>:finished`: number of tasks that have been marked as "Done" for a certain stage. - `tq:qds:<dataset>:<stage>:running`: set of all `task_id`s of tasks currently running for a certain stage. - `tq:qds:<dataset>:<stage>:pending`: set of all `task_id`s of tasks currently pending for a certain stage. **Worker** The parent class of all workers used in aleph: the Aleph worker, the `ingest-file` worker. Handles the consuming of tasks from RabbitMQ queues, and sending acknowledgements when the tasks are completed. The `dispatch_task` method is implemented in each subsequent child class. ### Changes from the initial RabbitMQ implementation - implemented **priorities** for tasks. Each task gets assigned a random priority. The Producer will also reserve a maximum priority for tasks that need to be queued and executed urgently. This maximum priority implementation will exist outside of `servicelayer`. - added **Redis keys**: `tq:qds:<dataset>:<stage>` (`stage_key`), `tq:qds:<dataset>:<stage>:finished`, `tq:qds:<dataset>:<stage>:running`, `tq:qds:<dataset>:<stage>:pending` and added code to `get_status` to expose a break-down of tasks per stage. **The `job_id` key is set to `null` since jobs are no longer relevant. The key was preserved in the JSON in order to not introduce breaking changes.** - `get_rabbitmq_connection` has been refactored and it will now **re-establish a new RabbitMQ connection** is the existing one was closed. ### Other changes The **status API JSON response** has been modified, introducing a **breaking change**. The **jobs** key has been removed from the JSON. Now, the JSON contains a total number of running, pending and finished tasks, as well as a break-down of these tasks **per stage**.
- Loading branch information