pub struct Task { /* private fields */ }Expand description
Stored Task resource.
The serialized shape is apiVersion, kind, metadata, spec, status.
Name, UID, and creation time are preserved by Self::apply_desired.
Implementations§
Source§impl Task
impl Task
Sourcepub fn new(name: impl AsRef<str>, spec: TaskSpec) -> ModelResult<Self>
pub fn new(name: impl AsRef<str>, spec: TaskSpec) -> ModelResult<Self>
Creates a stored Task with server-owned defaults.
The UID and creation timestamp are generated, generation starts at 1, and status starts as unobserved Pending.
The state store assigns the initial resource version separately.
§Errors
Returns ModelError::Invalid when the name or spec is invalid, or the entropy source is unavailable.
Sourcepub fn from_manifest(manifest: TaskManifest) -> ModelResult<Self>
pub fn from_manifest(manifest: TaskManifest) -> ModelResult<Self>
Creates a stored resource from a manifest.
§Errors
Returns ModelError::Invalid when the manifest is invalid or the entropy source is unavailable.
Sourcepub fn from_parts(
type_meta: TypeMeta,
metadata: ObjectMeta,
spec: TaskSpec,
status: TaskStatus,
) -> ModelResult<Self>
pub fn from_parts( type_meta: TypeMeta, metadata: ObjectMeta, spec: TaskSpec, status: TaskStatus, ) -> ModelResult<Self>
Reconstructs a resource from persisted fields.
§Errors
Returns ModelError::Invalid when a resource invariant is violated.
Sourcepub fn validate(&self) -> ModelResult<()>
pub fn validate(&self) -> ModelResult<()>
Validates the complete resource.
§Errors
Returns ModelError::Invalid when GVK, metadata, spec, status, generation, or conditions are inconsistent.
Sourcepub fn metadata(&self) -> &ObjectMeta
pub fn metadata(&self) -> &ObjectMeta
Resource metadata.
Sourcepub fn status(&self) -> &TaskStatus
pub fn status(&self) -> &TaskStatus
Observed state.
Sourcepub fn into_parts(self) -> (TypeMeta, ObjectMeta, TaskSpec, TaskStatus)
pub fn into_parts(self) -> (TypeMeta, ObjectMeta, TaskSpec, TaskStatus)
Returns the serialized resource fields.
Sourcepub fn set_resource_version(
&mut self,
resource_version: impl Into<String>,
) -> ModelResult<()>
pub fn set_resource_version( &mut self, resource_version: impl Into<String>, ) -> ModelResult<()>
Assigns a state-store resource version.
§Errors
Returns ModelError::Invalid when the value is empty.
Sourcepub fn apply_desired(
&mut self,
labels: Labels,
annotations: Annotations,
spec: TaskSpec,
resource_version: impl Into<String>,
) -> ModelResult<DesiredChange>
pub fn apply_desired( &mut self, labels: Labels, annotations: Annotations, spec: TaskSpec, resource_version: impl Into<String>, ) -> ModelResult<DesiredChange>
Applies caller-owned metadata and desired state.
UID and creation time are preserved.
Metadata-only changes preserve generation and status.
Spec changes increment generation and reset phase and attempt.
The previous observedGeneration is retained.
Identical desired state returns DesiredChange::None.
In that case, resource_version is not assigned.
§Errors
Returns ModelError::Invalid when metadata, spec, or a changed resource_version is invalid.
Sourcepub fn mark_observed(
&mut self,
resource_version: impl Into<String>,
) -> ModelResult<bool>
pub fn mark_observed( &mut self, resource_version: impl Into<String>, ) -> ModelResult<bool>
Marks the current generation as reconciled.
Returns true when status changed.
Returns false when the same generation was already reconciled.
§Errors
Returns ModelError::Invalid when a changed resource_version is empty.
Sourcepub fn mark_reconciliation_pending(
&mut self,
resource_version: impl Into<String>,
) -> ModelResult<bool>
pub fn mark_reconciliation_pending( &mut self, resource_version: impl Into<String>, ) -> ModelResult<bool>
Reschedules reconciliation after a recorded failure.
Returns false when reconciliation is not failed.
A change resets phase, attempt, exit code, and lifecycle error.
§Errors
Returns ModelError::Invalid when a changed resource_version is empty.
Sourcepub fn mark_reconciliation_failed(
&mut self,
reason: impl Into<String>,
message: impl Into<String>,
resource_version: impl Into<String>,
) -> ModelResult<bool>
pub fn mark_reconciliation_failed( &mut self, reason: impl Into<String>, message: impl Into<String>, resource_version: impl Into<String>, ) -> ModelResult<bool>
Records a reconciliation failure.
Desired state is retained. Execution phase and diagnostics are reset.
Returns true when status changed.
§Errors
Returns ModelError::Invalid when reason, message, or a changed resource_version is invalid.
Sourcepub fn transition_starting(
&mut self,
generation: u64,
attempt: u32,
resource_version: impl Into<String>,
) -> ModelResult<bool>
pub fn transition_starting( &mut self, generation: u64, attempt: u32, resource_version: impl Into<String>, ) -> ModelResult<bool>
Records an authoritative attempt start.
A stale generation returns false.
An identical transition also returns false.
Attempt numbers come from the execution source of truth.
§Errors
Returns ModelError::Invalid when the current generation has attempt zero or a changed resource_version is empty.
Sourcepub fn transition_finished(
&mut self,
generation: u64,
attempt: u32,
phase: TaskPhase,
error: Option<String>,
exit_code: Option<i32>,
resource_version: impl Into<String>,
) -> ModelResult<bool>
pub fn transition_finished( &mut self, generation: u64, attempt: u32, phase: TaskPhase, error: Option<String>, exit_code: Option<i32>, resource_version: impl Into<String>, ) -> ModelResult<bool>
Records a terminal attempt phase.
A stale generation or older attempt returns false.
Terminal phases are sticky.
Failed may be refined to Exhausted or Timeout.
§Errors
Returns ModelError::Invalid when the current generation has attempt zero, phase is not terminal, or a changed resource_version is empty.
Sourcepub fn reconcile_finished(
&mut self,
generation: u64,
phase: TaskPhase,
error: Option<String>,
exit_code: Option<i32>,
resource_version: impl Into<String>,
) -> ModelResult<bool>
pub fn reconcile_finished( &mut self, generation: u64, phase: TaskPhase, error: Option<String>, exit_code: Option<i32>, resource_version: impl Into<String>, ) -> ModelResult<bool>
Records an authoritative final lifecycle outcome.
Unlike Self::transition_finished, this may replace a conflicting terminal attempt phase.
A stale generation or identical outcome returns false.
§Errors
Returns ModelError::Invalid when phase is not terminal for the current generation or a changed resource_version is empty.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Task
impl<'de> Deserialize<'de> for Task
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Task
Source§impl From<&Task> for TaskManifest
impl From<&Task> for TaskManifest
Source§impl From<Task> for TaskManifest
impl From<Task> for TaskManifest
Source§impl JsonSchema for Task
impl JsonSchema for Task
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more