pub struct WorkflowContext { /* private fields */ }Expand description
Standard workflow context for n8n-style execution engines.
Provides common workflow execution metadata that most workflow engines need. This is a convenience struct that workflow engines can use directly or extend.
§Examples
use ferrous_di::{ServiceCollection, ScopeLocal, WorkflowContext, Resolver};
use std::sync::Arc;
let mut services = ServiceCollection::new();
services.add_scope_local::<WorkflowContext, _>(|_resolver| {
Arc::new(WorkflowContext::new("user_onboarding"))
});
services.add_scoped_factory::<String, _>(|resolver| {
let ctx = resolver.get_required::<ScopeLocal<WorkflowContext>>();
format!("Executing step in workflow '{}' (run: {})",
ctx.workflow_name(),
ctx.run_id())
});
let provider = services.build();
let scope = provider.create_scope();
let status = scope.get_required::<String>();Implementations§
Source§impl WorkflowContext
impl WorkflowContext
Sourcepub fn new(workflow_name: impl Into<String>) -> Self
pub fn new(workflow_name: impl Into<String>) -> Self
Creates a new workflow context with an auto-generated run ID.
Sourcepub fn with_run_id(
workflow_name: impl Into<String>,
run_id: impl Into<String>,
) -> Self
pub fn with_run_id( workflow_name: impl Into<String>, run_id: impl Into<String>, ) -> Self
Creates a new workflow context with a specific run ID.
Sourcepub fn workflow_name(&self) -> &str
pub fn workflow_name(&self) -> &str
Gets the workflow name.
Sourcepub fn started_at(&self) -> Instant
pub fn started_at(&self) -> Instant
Gets the start time for this workflow execution.
Sourcepub fn add_metadata(&mut self, key: impl Into<String>, value: impl Into<String>)
pub fn add_metadata(&mut self, key: impl Into<String>, value: impl Into<String>)
Adds metadata to the workflow context.
Sourcepub fn get_metadata(&self, key: &str) -> Option<&String>
pub fn get_metadata(&self, key: &str) -> Option<&String>
Gets metadata from the workflow context.
Trait Implementations§
Source§impl Clone for WorkflowContext
impl Clone for WorkflowContext
Source§fn clone(&self) -> WorkflowContext
fn clone(&self) -> WorkflowContext
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for WorkflowContext
impl Debug for WorkflowContext
Source§impl Default for WorkflowContext
impl Default for WorkflowContext
Source§impl WorkflowContextProvider for WorkflowContext
Helper for integrating with ScopeLocal workflow contexts.
impl WorkflowContextProvider for WorkflowContext
Helper for integrating with ScopeLocal workflow contexts.
Source§fn observation_context(&self) -> ObservationContext
fn observation_context(&self) -> ObservationContext
Extracts observation context from the workflow state.
Auto Trait Implementations§
impl Freeze for WorkflowContext
impl RefUnwindSafe for WorkflowContext
impl Send for WorkflowContext
impl Sync for WorkflowContext
impl Unpin for WorkflowContext
impl UnwindSafe for WorkflowContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more