Skip to main content

apalis_core/backend/persistence/
event.rs

1use crate::{backend::TaskResult, task::task_id::TaskId};
2
3/// A message representing a state transition or event for a task within
4/// the task processing system.
5///
6/// `Res` is the task's associated output/payload type, and `Id` is the
7/// underlying identifier type used to uniquely reference a task.
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[derive(Debug, Clone)]
10#[non_exhaustive]
11pub enum TaskEvent<Res> {
12    /// Signals that a task has finished processing, carrying its result.
13    ///
14    /// This is sent once a worker has finished executing a task,
15    /// regardless of whether it succeeded or failed — the outcome itself
16    /// is encoded in [`TaskResult`].
17    Complete(TaskResult<Res>),
18
19    /// Requests that a lock has been acquired on the given
20    /// task, preventing other workers from picking it up concurrently.
21    Lock {
22        /// The identifier of the task being locked.
23        task_id: TaskId,
24    },
25
26    /// Releases a previously acquired lock on the given task, making it
27    /// available for other workers to claim.
28    ///
29    /// This is typically sent after a task completes, fails, or its lock
30    /// needs to be freed without marking the task as complete (e.g. on
31    /// worker shutdown).
32    Release {
33        /// The identifier of the task whose lock is being released.
34        task_id: TaskId,
35    },
36
37    /// Requests that the given task be cancelled.
38    ///
39    /// This may be sent before a task has started, or while it is in
40    /// progress, depending on what the consuming system supports.
41    Cancel {
42        /// The identifier of the task being cancelled.
43        task_id: TaskId,
44    },
45}