Skip to main content

WorkflowTask

Trait WorkflowTask 

Source
pub trait WorkflowTask: Send + Sync {
    // Required methods
    fn execute<'life0, 'life1, 'async_trait>(
        &'life0 self,
        context: &'life1 TaskContext,
    ) -> Pin<Box<dyn Future<Output = Result<TaskResult, TaskError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn id(&self) -> TaskId;
    fn name(&self) -> &str;

    // Provided methods
    fn dependencies(&self) -> Vec<TaskId> { ... }
    fn compensation(&self) -> Option<CompensationAction> { ... }
}
Expand description

Trait for workflow task execution.

All workflow tasks must implement this trait to enable execution by the WorkflowExecutor. Tasks are executed asynchronously in topological order based on their dependencies.

Required Methods§

Source

fn execute<'life0, 'life1, 'async_trait>( &'life0 self, context: &'life1 TaskContext, ) -> Pin<Box<dyn Future<Output = Result<TaskResult, TaskError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Executes the task with the provided context.

§Arguments
  • context - Execution context with Forge instance and metadata
§Returns

Returns Ok(TaskResult) on success, or Err(TaskError) on failure.

Source

fn id(&self) -> TaskId

Returns the unique task identifier.

Source

fn name(&self) -> &str

Returns the human-readable task name.

Provided Methods§

Source

fn dependencies(&self) -> Vec<TaskId>

Returns the list of task dependencies.

Default implementation returns an empty vector (no dependencies).

Source

fn compensation(&self) -> Option<CompensationAction>

Returns the compensation action for this task (if any).

Compensation actions are used during workflow rollback to undo task side effects using the Saga pattern. Tasks that don’t have side effects (e.g., read-only queries) should return None.

Default implementation returns None (no compensation).

§Returns
  • Some(CompensationAction) - Task can be compensated
  • None - Task has no compensation (will be skipped during rollback)

Implementors§