Skip to main content

TaskState

Struct TaskState 

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

In-memory task state storage.

§Also

  • StateConfig TTL settings consumed by sweep.
  • [StateSubscriber] wires taskvisor events into mutations.
  • [state_sweep] builds an embedded periodic sweep task.

Implementations§

Source§

impl TaskState

Source

pub fn new() -> Self

Create empty task state.

Source

pub fn add_task(&self, id: TaskId, spec: TaskSpec)

Register a new task (called on TaskAdded event).

Source

pub fn unregister_task(&self, id: &TaskId)

Unregister a task from state (called on TaskRemoved event).

Removes the task entry and its slot index, but preserves run history (cleaned later by sweep). Compare with delete_task which removes both.

Source

pub fn delete_task(&self, id: &TaskId) -> bool

Delete a task and its run history. Returns true if the task existed.

This is the API-driven full removal. Compare with unregister_task which preserves runs.

Source

pub fn transition_starting(&self, id: &TaskId) -> Option<u32>

Atomically transition a task to Running.

Source

pub fn transition_finished( &self, id: &TaskId, phase: TaskPhase, error: Option<String>, exit_code: Option<i32>, ) -> bool

Atomically transition a task to a terminal phase and close the active run.

Source

pub fn list_runs(&self, id: &TaskId) -> Vec<TaskRun>

List all runs for a task (oldest first).

Source

pub fn get(&self, id: &TaskId) -> Option<Task>

Get task by ID.

Source

pub fn list_by_slot(&self, slot: &str) -> Vec<Task>

List all tasks in a specific slot.

Source

pub fn list_all(&self) -> Vec<Task>

List all tasks.

Source

pub fn list_by_status(&self, phase: TaskPhase) -> Vec<Task>

List tasks matching a phase filter.

Source

pub fn sweep(&self, config: &StateConfig) -> (usize, usize)

Run a sweep pass.

Two passes under a single write lock:

  1. Remove finished runs older than run_ttl.
  2. Remove terminal tasks that have no remaining runs and whose updated_at is older than task_ttl.

Returns (runs_removed, tasks_removed) for observability.

Source

pub fn query(&self, q: &TaskQuery) -> TaskPage<Task>

Query tasks with combined filters and pagination.

Filters are applied inside a single read lock. When slot is specified, uses the by_slot index to narrow the scan. total in the result reflects the count after filtering, before pagination.

Trait Implementations§

Source§

impl Clone for TaskState

Source§

fn clone(&self) -> TaskState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for TaskState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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> 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.
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