pub struct TaskState { /* private fields */ }Expand description
In-memory task state storage.
§Also
StateConfigTTL settings consumed bysweep.- [
StateSubscriber] wires taskvisor events into mutations. - [
state_sweep] builds an embedded periodic sweep task.
Implementations§
Source§impl TaskState
impl TaskState
Sourcepub fn add_task(&self, id: TaskId, spec: TaskSpec)
pub fn add_task(&self, id: TaskId, spec: TaskSpec)
Register a new task (called on TaskAdded event).
Sourcepub fn unregister_task(&self, id: &TaskId)
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.
Sourcepub fn delete_task(&self, id: &TaskId) -> bool
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.
Sourcepub fn transition_starting(&self, id: &TaskId) -> Option<u32>
pub fn transition_starting(&self, id: &TaskId) -> Option<u32>
Atomically transition a task to Running.
Sourcepub fn transition_finished(
&self,
id: &TaskId,
phase: TaskPhase,
error: Option<String>,
exit_code: Option<i32>,
) -> bool
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.
Sourcepub fn list_by_slot(&self, slot: &str) -> Vec<Task>
pub fn list_by_slot(&self, slot: &str) -> Vec<Task>
List all tasks in a specific slot.
Sourcepub fn list_by_status(&self, phase: TaskPhase) -> Vec<Task>
pub fn list_by_status(&self, phase: TaskPhase) -> Vec<Task>
List tasks matching a phase filter.
Sourcepub fn sweep(&self, config: &StateConfig) -> (usize, usize)
pub fn sweep(&self, config: &StateConfig) -> (usize, usize)
Run a sweep pass.
Two passes under a single write lock:
- Remove finished runs older than
run_ttl. - Remove terminal tasks that have no remaining runs and whose
updated_atis older thantask_ttl.
Returns (runs_removed, tasks_removed) for observability.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TaskState
impl !RefUnwindSafe for TaskState
impl Send for TaskState
impl Sync for TaskState
impl Unpin for TaskState
impl UnsafeUnpin for TaskState
impl !UnwindSafe for TaskState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more