Interface IStepDispatcher
- Namespace
- FlowOrchestrator.Core.Execution
- Assembly
- FlowOrchestrator.Core.dll
Bridges the core engine to the runtime that physically invokes RunStepAsync(IExecutionContext, IFlowDefinition, IStepInstance, CancellationToken) — Hangfire today, a queue consumer or in-memory channel tomorrow — without the engine knowing which one is active.
public interface IStepDispatcher
Remarks
Implementations must guarantee that all arguments are serialisable by the backing runtime so that a different worker process can deserialise and re-enter the engine.
Properties
LosesQueuedStepsOnRestart
Whether a step this dispatcher has accepted (enqueued or scheduled) is LOST when the process that accepted it stops — true for an in-process queue, false for a runtime backed by durable storage (Hangfire job storage, a Service Bus queue).
bool LosesQueuedStepsOnRestart { get; }
Property Value
Remarks
Startup recovery reads this to interpret the dispatch ledger. Every dispatched step carries a ledger
row in the run store; on a durable runtime a ledger row means "the runtime still holds this step and
will deliver it", so recovery leaves it alone. On a non-durable runtime the queued work died with the
process while the row survived (the run store can be durable even when the runtime is not, e.g.
UseInMemoryRuntime() with UseSqlServer()), so recovery re-enqueues every ledgered step
that has not started — including a Pending poll whose delayed re-attempt was lost — without
recording a second ledger row. The execution claim still guarantees a step runs once.
Defaults to false (durable), so existing runtimes keep their behaviour. The polarity
is deliberate: a mocking library that returns default(bool) for an un-configured member
reproduces the durable behaviour every pre-2.0 test was written against. A decorator around another
dispatcher must forward this property.
Methods
EnqueueStepAsync(IExecutionContext, IFlowDefinition, IStepInstance, CancellationToken)
Enqueues immediate execution of a step.
ValueTask<string?> EnqueueStepAsync(IExecutionContext context, IFlowDefinition flow, IStepInstance step, CancellationToken ct = default)
Parameters
contextIExecutionContextThe current execution context carrying RunId, trigger data, and principal.
flowIFlowDefinitionThe flow definition the step belongs to.
stepIStepInstanceThe step instance to execute.
ctCancellationTokenCancellation token.
Returns
- ValueTask<string>
An opaque runtime-specific job or message identifier, or null if the runtime does not produce one. The engine records it on the step's dispatch-ledger row once this call returns; that annotation is how a completed hand-off is told apart from one that never returned, which
FlowUnsentDispatchRecoveryHostedServicere-delivers.
ScheduleStepAsync(IExecutionContext, IFlowDefinition, IStepInstance, TimeSpan, CancellationToken)
Schedules deferred execution of a step after delay has elapsed.
Used for polling steps (Pending), backoff retries, and runAfter-with-delay scenarios.
ValueTask<string?> ScheduleStepAsync(IExecutionContext context, IFlowDefinition flow, IStepInstance step, TimeSpan delay, CancellationToken ct = default)
Parameters
contextIExecutionContextThe current execution context.
flowIFlowDefinitionThe flow definition the step belongs to.
stepIStepInstanceThe step instance to execute.
delayTimeSpanHow long to wait before the step is eligible to run.
ctCancellationTokenCancellation token.
Returns
- ValueTask<string>
An opaque runtime-specific job or message identifier, or null; recorded as for EnqueueStepAsync(IExecutionContext, IFlowDefinition, IStepInstance, CancellationToken).