Skip to main content

RunInstance

Struct RunInstance 

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

A run instance represents a specific scheduled occurrence of a task.

Each run is uniquely identified by a RunId and is associated with a TaskId. The lifecycle of a run progresses through canonical states according to the run policy.

Implementations§

Source§

impl RunInstance

Source

pub fn new_scheduled( task_id: TaskId, scheduled_at: u64, created_at: u64, ) -> Result<Self, RunInstanceConstructionError>

Creates a new run instance in Scheduled state.

Source

pub fn new_scheduled_with_id( id: RunId, task_id: TaskId, scheduled_at: u64, created_at: u64, ) -> Result<Self, RunInstanceConstructionError>

Creates a new run instance in Scheduled state with an explicit identifier.

This constructor is primarily intended for deterministic replay/bootstrap flows that must preserve a durable RunId.

Source

pub fn new_ready( task_id: TaskId, scheduled_at: u64, created_at: u64, effective_priority: i32, ) -> Result<Self, RunInstanceConstructionError>

Creates a new ready run with the specified effective priority.

Source

pub fn new_ready_with_id( id: RunId, task_id: TaskId, scheduled_at: u64, created_at: u64, effective_priority: i32, ) -> Result<Self, RunInstanceConstructionError>

Creates a new ready run with an explicit identifier and effective priority.

Source

pub fn is_terminal(&self) -> bool

Returns true if this run is in a terminal state.

Source

pub fn id(&self) -> RunId

Returns this run’s identifier.

Source

pub fn task_id(&self) -> TaskId

Returns the owning task identifier for this run.

Source

pub fn state(&self) -> RunState

Returns the current lifecycle state for this run.

Source

pub fn current_attempt_id(&self) -> Option<AttemptId>

Returns the currently active attempt identifier, if one exists.

Source

pub fn attempt_count(&self) -> u32

Returns the number of started attempts for this run.

Source

pub fn created_at(&self) -> u64

Returns the run creation timestamp.

Source

pub fn scheduled_at(&self) -> u64

Returns the timestamp at which this run becomes eligible for readiness.

Source

pub fn effective_priority(&self) -> i32

Returns the effective priority snapshot currently associated with this run.

Source

pub fn last_state_change_at(&self) -> u64

Returns the timestamp of the most recent state change.

Source

pub fn record_state_change_at(&mut self, timestamp: u64)

Records the timestamp of a state change (called by the reducer after transitions).

§Invariants

In production, the supplied timestamp must be monotonically non-decreasing relative to the current last_state_change_at. The reducer is the sole caller and is expected to feed wall-clock timestamps from durably ordered WAL events. Violation of this invariant will not cause incorrect behavior (the field is simply overwritten), but it indicates a clock or sequencing anomaly that should be investigated.

Source

pub fn transition_to( &mut self, new_state: RunState, ) -> Result<(), RunInstanceError>

Applies a validated lifecycle transition.

Transition legality is enforced via the canonical transition table. Leaving Running while an active attempt is still open is rejected.

Source

pub fn promote_to_ready(&mut self) -> Result<(), RunInstanceError>

Promotes this run into the Ready state with transition validation.

Source

pub fn promote_to_ready_with_priority( &mut self, effective_priority: i32, ) -> Result<(), RunInstanceError>

Promotes this run into the Ready state and snapshots its effective priority.

Source

pub fn set_effective_priority( &mut self, effective_priority: i32, ) -> Result<(), RunInstanceError>

Updates the ready-state effective priority snapshot.

Source

pub fn start_attempt( &mut self, attempt_id: AttemptId, ) -> Result<(), RunInstanceError>

Records the start of a new attempt for a run currently in Running.

Source

pub fn finish_attempt( &mut self, attempt_id: AttemptId, ) -> Result<(), RunInstanceError>

Records completion of the current active attempt.

Source§

impl RunInstance

Source

pub fn restore_attempt_state_for_bootstrap( &mut self, count: u32, active_attempt: Option<AttemptId>, )

Restores attempt state during snapshot bootstrap.

During snapshot bootstrap, runs are created via new_scheduled_with_id (which initializes attempt_count=0 and current_attempt_id=None) then replayed through state transitions. However, start_attempt()/finish_attempt() are never called during bootstrap replay. This method directly sets the attempt count and active attempt ID from the snapshot’s attempt history.

This is a bootstrap-only method — normal operation uses start_attempt() and finish_attempt() which enforce state-machine invariants.

Trait Implementations§

Source§

impl Clone for RunInstance

Source§

fn clone(&self) -> RunInstance

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RunInstance

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for RunInstance

Source§

fn eq(&self, other: &RunInstance) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for RunInstance

Source§

impl StructuralPartialEq for RunInstance

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.