forge_core/function/
dispatch.rs

1use std::future::Future;
2use std::pin::Pin;
3
4use uuid::Uuid;
5
6use crate::error::Result;
7
8/// Trait for dispatching jobs from function contexts.
9///
10/// This trait allows mutation and action contexts to dispatch background jobs
11/// without directly depending on the runtime's JobDispatcher.
12pub trait JobDispatch: Send + Sync {
13    /// Dispatch a job by its registered name.
14    ///
15    /// # Arguments
16    /// * `job_type` - The registered name of the job type
17    /// * `args` - JSON-serialized arguments for the job
18    ///
19    /// # Returns
20    /// The UUID of the dispatched job
21    fn dispatch_by_name(
22        &self,
23        job_type: &str,
24        args: serde_json::Value,
25    ) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + '_>>;
26}
27
28/// Trait for starting workflows from function contexts.
29///
30/// This trait allows mutation and action contexts to start workflows
31/// without directly depending on the runtime's WorkflowExecutor.
32pub trait WorkflowDispatch: Send + Sync {
33    /// Start a workflow by its registered name.
34    ///
35    /// # Arguments
36    /// * `workflow_name` - The registered name of the workflow
37    /// * `input` - JSON-serialized input for the workflow
38    ///
39    /// # Returns
40    /// The UUID of the started workflow run
41    fn start_by_name(
42        &self,
43        workflow_name: &str,
44        input: serde_json::Value,
45    ) -> Pin<Box<dyn Future<Output = Result<Uuid>> + Send + '_>>;
46}