Skip to main content

DispatchLoop

Struct DispatchLoop 

Source
pub struct DispatchLoop<W: WalWriter, H: ExecutorHandler, C: Clock = SystemClock, I: ExecutorIdentity = LocalExecutorIdentity> { /* private fields */ }
Expand description

The core dispatch loop that composes all engine primitives.

Workers execute handler logic via tokio::task::spawn_blocking and send results back through an unbounded MPSC channel. All WAL mutation authority remains exclusively owned by the dispatch loop — workers never touch the WAL.

The I: ExecutorIdentity generic defaults to LocalExecutorIdentity so existing construction sites don’t need changes for v0.x. Sprint 4 remote actors will supply their own identity via this parameter.

Implementations§

Source§

impl<W: WalWriter, H: ExecutorHandler + 'static, C: Clock> DispatchLoop<W, H, C>

Source

pub fn new( authority: StorageMutationAuthority<W, ReplayReducer>, handler: H, clock: C, config: DispatchConfig, ) -> Result<Self, DispatchError>

Creates a new dispatch loop.

§Errors

Returns DispatchError::InvalidBackoffConfig if the backoff strategy configuration is invalid (e.g., exponential base exceeds max).

Source

pub fn projection(&self) -> &ReplayReducer

Returns a reference to the projection (current state view).

Source

pub async fn tick(&mut self) -> Result<TickResult, DispatchError>

Advances the state machine one step.

A tick performs: 0a. Drain workflow submissions from handlers (non-blocking) 0b. Drain completed worker results (non-blocking) 0c. Cascade hierarchy cancellations to descendants of canceled tasks 0c-gc. GC terminal tasks from in-memory data structures 0d. Derive new cron runs to maintain the rolling window (workflow feature) 0f. Check actor heartbeat timeouts (actor feature)

  1. Heartbeat in-flight leases approaching expiry
  2. Check engine paused state — skip if paused
  3. Promote Scheduled → Ready (time-based)
  4. Promote RetryWait → Ready (backoff-based)
  5. Select ready runs (priority-FIFO-RunId)
  6. For each selected: check concurrency key gate → lease → dispatch (spawn worker)
Source

pub async fn run_until_idle(&mut self) -> Result<RunSummary, DispatchError>

Loops tick() until no work remains (no in-flight, no promotions, no dispatches).

Source

pub fn start_drain(&mut self)

Begins graceful drain: stops promoting and dispatching new work, but continues processing in-flight results and heartbeating leases.

Source

pub async fn drain_until_idle( &mut self, timeout: Duration, ) -> Result<RunSummary, DispatchError>

Drains in-flight work until idle or the timeout expires.

Source

pub fn submit_task(&mut self, spec: TaskSpec) -> Result<(), DispatchError>

Submits a new task and derives initial runs.

Source

pub fn declare_dependency( &mut self, task_id: TaskId, prereqs: Vec<TaskId>, ) -> Result<(), DispatchError>

Declares a DAG dependency: task_id may not promote until all prereqs complete.

Validates cycle-freedom and prerequisite existence before WAL-appending.

Source

pub fn into_authority(self) -> StorageMutationAuthority<W, ReplayReducer>

Consumes the dispatch loop and returns the mutation authority.

Auto Trait Implementations§

§

impl<W, H, C, I> Freeze for DispatchLoop<W, H, C, I>
where C: Freeze, I: Freeze, W: Freeze,

§

impl<W, H, C = SystemClock, I = LocalExecutorIdentity> !RefUnwindSafe for DispatchLoop<W, H, C, I>

§

impl<W, H, C, I> Send for DispatchLoop<W, H, C, I>
where W: Send,

§

impl<W, H, C, I> Sync for DispatchLoop<W, H, C, I>
where W: Sync,

§

impl<W, H, C, I> Unpin for DispatchLoop<W, H, C, I>
where C: Unpin, I: Unpin, W: Unpin,

§

impl<W, H, C, I> UnsafeUnpin for DispatchLoop<W, H, C, I>

§

impl<W, H, C = SystemClock, I = LocalExecutorIdentity> !UnwindSafe for DispatchLoop<W, H, C, I>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more