Skip to main content

WorkloopService

Struct WorkloopService 

Source
pub struct WorkloopService { /* private fields */ }
Expand description

The engine-side cadence service. One instance, one sweep task, N loops.

Implementations§

Source§

impl WorkloopService

Source

pub fn new( store: Arc<dyn WorkloopStore>, sink: Arc<dyn LoopEventSink>, waker: Arc<dyn WorkloopWaker>, sweep_interval: Duration, ) -> Result<Self, WorkloopError>

Creates the service. sweep_interval is the operator-declared sweep cadence — REQUIRED, never defaulted, and it bounds dead-man detection latency.

§Errors

Refuses a zero interval (WorkloopError::ZeroSweepInterval).

Source

pub fn with_clock( store: Arc<dyn WorkloopStore>, sink: Arc<dyn LoopEventSink>, waker: Arc<dyn WorkloopWaker>, sweep_interval: Duration, now: impl Fn() -> DateTime<Utc> + Send + Sync + 'static, ) -> Result<Self, WorkloopError>

WorkloopService::new with an injected clock, for deterministic tests.

§Errors

Refuses a zero interval (WorkloopError::ZeroSweepInterval).

Source

pub const fn sweep_interval(&self) -> Duration

The declared sweep interval.

Source

pub async fn register( &self, loop_id: WorkflowId, namespace: String, spec: WorkloopSpec, ) -> Result<WorkloopRecord, WorkloopError>

Registers a loop: persists its declared spec and arms the first cadence window (and/or duration deadlines) on the sweep set.

§Errors

Refuses a duplicate registration and propagates store failures.

Source

pub async fn wake_now(&self, loop_id: &WorkflowId) -> Result<(), WorkloopError>

Wakes a loop’s current generation immediately — the signal-armed fire (R2.4): a declared signal arrived, so the iteration runs now, no window involved.

§Errors

Propagates the waker’s failure.

Source

pub async fn deregister( &self, loop_id: &WorkflowId, ) -> Result<bool, WorkloopError>

Deregisters a loop (retirement or death). Invariant current-state records are untouched — the current record survives indefinitely (R8.1).

§Errors

Propagates store failures.

Source

pub async fn note_iteration_closed( &self, loop_id: &WorkflowId, samples: &[HealthSample], ) -> Result<Vec<InvariantAlarm>, WorkloopError>

Feed an iteration close into health accounting (R3.3): every declared invariant is sampled on the same tick — Confirmed resets its accounting, Unconfirmed accrues red-sample evidence and may exceed the count-form tolerance immediately. Returns the alarms raised.

§Errors

Refuses samples naming undeclared invariants; propagates store and append failures.

Source

pub async fn tick(&self) -> Result<SweepReport, WorkloopError>

One sweep pass over every due loop: fire elapsed cadence windows (recording CadenceFired through the one Recorder, then waking the generation), evaluate the dead-man switch (an iteration with no terminal by its next window is a missed window — R3.3a — counted against every invariant), and evaluate every declared tolerance, raising InvariantUnconfirmed with its cause on the one alarm path.

§Errors

Returns an error only when the due-set itself cannot be read; per-loop faults are carried in the report so one sick loop cannot silence the sweep for the rest.

Source

pub async fn run(self: Arc<Self>, shutdown: Receiver<bool>)

Runs the sweep loop until shutdown flips true. One task for every loop in the store — never a task per loop.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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