apalis_workflow/
router.rs

1use std::{collections::HashMap, time::Duration};
2
3use apalis_core::{backend::BackendExt, task::task_id::TaskId};
4use serde::{Deserialize, Serialize};
5
6use crate::SteppedService;
7
8/// Router for workflow steps
9#[derive(Debug, Default)]
10pub struct WorkflowRouter<Backend>
11where
12    Backend: BackendExt,
13{
14    pub(super) steps:
15        HashMap<usize, SteppedService<Backend::Compact, Backend::Context, Backend::IdType>>,
16}
17
18impl<Backend> WorkflowRouter<Backend>
19where
20    Backend: BackendExt,
21{
22    /// Create a new workflow router
23    #[must_use]
24    pub fn new() -> Self {
25        Self {
26            steps: HashMap::new(),
27        }
28    }
29}
30/// Result information for workflow steps
31#[derive(Debug, Clone, Deserialize, Serialize, Default)]
32pub struct StepResult<Res, IdType> {
33    /// Result produced by the step
34    pub result: Res,
35    /// Optional ID of the next task to execute
36    pub next_task_id: Option<TaskId<IdType>>,
37}
38
39/// Enum representing the possible transitions in a workflow
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub enum GoTo<T = ()> {
42    /// Proceed to the next step with the given value
43    Next(T),
44    /// Delay the execution for the specified duration
45    DelayFor(Duration, T),
46    /// Break the workflow with the given value
47    Break(T),
48    /// Marks the workflow as done
49    Done,
50}