pub struct WorkflowRuntime<S>where
S: Store + WorkflowQueryStore,{ /* private fields */ }Expand description
Effect execution runtime.
The runtime coordinates effect and timer workers to process
effects from the outbox. It routes effects to the appropriate
workflow handler based on the workflow_type.
§Lifecycle
- Create with [
WorkflowRuntime::builder(store, WorkflowServiceConfig::default())] - Register workflows with
WorkflowBuilder::register() - Configure with
WorkflowBuilder::config() - Build with
WorkflowBuilder::build_runtime() - Run with
WorkflowRuntime::run()(not yet implemented)
§Example
let runtime = WorkflowRuntime::builder(store, WorkflowServiceConfig::default())
.register::<OrderWorkflow>(order_handler)
.build_runtime()?;
// Run until shutdown signal
runtime.run(shutdown_signal).await?;Implementations§
Source§impl<S> WorkflowRuntime<S>where
S: Store + WorkflowQueryStore,
impl<S> WorkflowRuntime<S>where
S: Store + WorkflowQueryStore,
Sourcepub fn builder(
store: S,
service_config: WorkflowServiceConfig,
) -> WorkflowBuilder<S>
pub fn builder( store: S, service_config: WorkflowServiceConfig, ) -> WorkflowBuilder<S>
Create a new runtime builder.
Sourcepub fn config(&self) -> &RuntimeConfig
pub fn config(&self) -> &RuntimeConfig
Returns the runtime configuration.
Sourcepub fn workflow_count(&self) -> usize
pub fn workflow_count(&self) -> usize
Returns the number of registered workflows.
Source§impl<S> WorkflowRuntime<S>
impl<S> WorkflowRuntime<S>
Sourcepub async fn run<F>(self, shutdown: F) -> Result<()>
pub async fn run<F>(self, shutdown: F) -> Result<()>
Run the effect and timer workers until shutdown signal.
This method starts workers which poll the outbox:
- Effect workers: process immediate effects via handlers
- Timer workers: process due timers by routing embedded inputs
The number of workers is controlled by effect_workers and
timer_workers in RuntimeConfig. Workers coordinate via
FOR UPDATE SKIP LOCKED to avoid processing the same effect twice.
§Shutdown Behavior
When the shutdown future completes:
- All workers stop claiming new work
- Wait for current work (if any) to complete
- Return cleanly after timeout
§Example
use tokio::signal;
let runtime = WorkflowRuntime::builder(pg_store, WorkflowServiceConfig::default())
.register(order_handler)
.config(RuntimeConfig {
effect_workers: 4, // 4 parallel effect workers
..Default::default()
})
.build_runtime()?;
// Run until Ctrl+C
runtime.run(async { signal::ctrl_c().await.ok(); }).await?;Sourcepub async fn fetch_dead_letters(
&self,
query: DeadLetterQuery,
) -> Result<Vec<DeadLetter>>
pub async fn fetch_dead_letters( &self, query: DeadLetterQuery, ) -> Result<Vec<DeadLetter>>
Fetch dead-lettered effects.
Returns effects that have exceeded the configured max_attempts
and are no longer being retried.
§Example
use ironflow::runtime::outbox::DeadLetterQuery;
// Fetch all dead letters
let dead_letters = runtime.fetch_dead_letters(DeadLetterQuery::new()).await?;
// Fetch dead letters for a specific workflow type
let order_dead_letters = runtime
.fetch_dead_letters(DeadLetterQuery::new().workflow_type("order"))
.await?;Sourcepub async fn count_dead_letters(&self, query: DeadLetterQuery) -> Result<u64>
pub async fn count_dead_letters(&self, query: DeadLetterQuery) -> Result<u64>
Sourcepub async fn retry_dead_letter(&self, effect_id: Uuid) -> Result<bool>
pub async fn retry_dead_letter(&self, effect_id: Uuid) -> Result<bool>
Retry a dead-lettered effect.
Resets the effect’s attempt count to 0, making it available for processing again by the effect worker.
Returns Ok(true) if the effect was found and reset,
Ok(false) if the effect was not found or already processed.
§Example
let dead_letters = runtime.fetch_dead_letters(DeadLetterQuery::new()).await?;
for dl in dead_letters {
runtime.retry_dead_letter(dl.id).await?;
}Sourcepub async fn fetch_timer_dead_letters(
&self,
query: DeadLetterQuery,
) -> Result<Vec<DeadLetter>>
pub async fn fetch_timer_dead_letters( &self, query: DeadLetterQuery, ) -> Result<Vec<DeadLetter>>
Fetch dead-lettered timers.
Sourcepub async fn count_timer_dead_letters(
&self,
query: DeadLetterQuery,
) -> Result<u64>
pub async fn count_timer_dead_letters( &self, query: DeadLetterQuery, ) -> Result<u64>
Count dead-lettered timers.
Sourcepub async fn retry_timer_dead_letter(&self, timer_id: Uuid) -> Result<bool>
pub async fn retry_timer_dead_letter(&self, timer_id: Uuid) -> Result<bool>
Retry a dead-lettered timer.
Trait Implementations§
Source§impl<S> Clone for WorkflowRuntime<S>
impl<S> Clone for WorkflowRuntime<S>
Source§fn clone(&self) -> WorkflowRuntime<S>
fn clone(&self) -> WorkflowRuntime<S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<S> Freeze for WorkflowRuntime<S>where
S: Freeze,
impl<S> !RefUnwindSafe for WorkflowRuntime<S>
impl<S> Send for WorkflowRuntime<S>
impl<S> Sync for WorkflowRuntime<S>
impl<S> Unpin for WorkflowRuntime<S>where
S: Unpin,
impl<S> !UnwindSafe for WorkflowRuntime<S>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more