Skip to main content

swf_runtime/tasks/
mod.rs

1mod call_runner;
2mod custom_runner;
3mod do_runner;
4mod emit_runner;
5mod for_runner;
6mod fork_runner;
7mod listen_runner;
8mod raise_runner;
9mod run_runner;
10mod set_runner;
11mod switch_runner;
12mod try_runner;
13mod wait_runner;
14
15pub(crate) use call_runner::CallTaskRunner;
16pub(crate) use custom_runner::CustomTaskRunner;
17pub(crate) use do_runner::DoTaskRunner;
18pub(crate) use emit_runner::EmitTaskRunner;
19pub(crate) use for_runner::ForTaskRunner;
20pub(crate) use fork_runner::ForkTaskRunner;
21pub(crate) use listen_runner::ListenTaskRunner;
22pub(crate) use raise_runner::RaiseTaskRunner;
23pub(crate) use run_runner::RunTaskRunner;
24pub(crate) use set_runner::SetTaskRunner;
25pub(crate) use switch_runner::SwitchTaskRunner;
26pub(crate) use try_runner::TryTaskRunner;
27pub(crate) use wait_runner::WaitTaskRunner;
28
29/// Macro to define a simple task runner with the standard `name + task` struct pattern.
30/// Generates the struct and `new()`.
31/// Note: Each runner must still provide its own `impl TaskRunner` with `task_name()` and `run()`.
32macro_rules! define_simple_task_runner {
33    ($( #[$meta:meta] )* $runner:ident, $task_ty:ty) => {
34        $( #[$meta] )*
35        pub struct $runner {
36            name: String,
37            task: $task_ty,
38        }
39
40        impl $runner {
41            pub fn new(name: &str, task: &$task_ty) -> crate::error::WorkflowResult<Self> {
42                Ok(Self {
43                    name: name.to_string(),
44                    task: task.clone(),
45                })
46            }
47        }
48    };
49}
50
51/// Generates the `task_name()` method for a TaskRunner impl.
52/// Use inside `impl TaskRunner for X { ... }` to avoid repeating `fn task_name() -> &str { &self.name }`.
53macro_rules! task_name_impl {
54    () => {
55        fn task_name(&self) -> &str {
56            &self.name
57        }
58    };
59}
60
61/// Creates default WorkflowContext and TaskSupport from a workflow reference.
62/// Use in tests to avoid repeating the 2-line initialization pattern.
63#[macro_export]
64macro_rules! default_support {
65    ($workflow:expr, $context:ident, $support:ident) => {
66        let mut $context = $crate::context::WorkflowContext::new(&$workflow).unwrap();
67        let mut $support = $crate::task_runner::TaskSupport::new(&$workflow, &mut $context);
68    };
69}
70
71pub(crate) use define_simple_task_runner;
72pub(crate) use task_name_impl;