pub struct Task { /* private fields */ }Expand description
Unified task resource.
Every task is represented as a single resource with three sections:
status- observed state: current phase, attempts, errors (TaskStatus)spec- desired state: what to run and how (TaskSpec)metadata- identity, versioning, timestamps (ObjectMeta)
§Also
TaskSpecdesired state (what to run, how to restart).TaskStatusobserved state (phase, attempt, exit code).TaskRunper-attempt execution record.ObjectMetaidentity and versioning.TaskPhaselifecycle state machine.
Implementations§
Source§impl Task
impl Task
Sourcepub fn new(id: TaskId, spec: TaskSpec) -> Self
pub fn new(id: TaskId, spec: TaskSpec) -> Self
Create a new task in TaskPhase::Pending phase.
Sourcepub fn metadata(&self) -> &ObjectMeta
pub fn metadata(&self) -> &ObjectMeta
Resource metadata (identity, resource_version, timestamps).
Sourcepub fn status(&self) -> &TaskStatus
pub fn status(&self) -> &TaskStatus
Observed state (phase, attempt, exit code, error).
Sourcepub fn into_parts(self) -> (ObjectMeta, TaskSpec, TaskStatus)
pub fn into_parts(self) -> (ObjectMeta, TaskSpec, TaskStatus)
Destructure into (metadata, spec, status). Used by transport
layers that need owned fields for serialization into wire types.
Sourcepub fn transition_starting(&mut self)
pub fn transition_starting(&mut self)
Transition the task into a new attempt: bumps attempt counter, sets phase to Running, clears error/exit_code.
Sourcepub fn transition_finished(
&mut self,
phase: TaskPhase,
error: Option<String>,
exit_code: Option<i32>,
) -> ModelResult<()>
pub fn transition_finished( &mut self, phase: TaskPhase, error: Option<String>, exit_code: Option<i32>, ) -> ModelResult<()>
Transition the current attempt into a terminal phase with optional error and exit code.
Rejects illegal transitions:
- target phase must be terminal (see
TaskPhase::is_terminal); finishing intoPendingorRunningis a logic bug upstream.
Sticky terminals: once an attempt has reached a specific final state
(Succeeded, Canceled, or Timeout), a later, conflicting terminal
event must not overwrite it. taskvisor emits two terminal events per run (the
per-attempt TaskStopped/TaskCanceled/TaskFailed followed by the
actor-level ActorExhausted/ActorDead); without this guard a trailing
ActorExhausted would flip a Canceled run into Exhausted. A
failure-class phase (Failed) is still allowed to be refined into a more
specific disposition (Exhausted/Timeout), and re-applying the same
phase is a harmless no-op.
Bumps resource_version only when the phase actually changes.