Skip to main content

TaskSpec

Struct TaskSpec 

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

Desired state for a task.

Use TaskSpec::builder to construct it. Resource constructors validate the completed spec.

§Example

use solti_model::{EmbeddedSpec, RestartPolicy, TaskSpec, TaskWorkload};

let workload = TaskWorkload::Embedded(EmbeddedSpec::new("v1").unwrap());
let spec = TaskSpec::builder("daily-cleanup", workload, 5_000u64)
    .restart(RestartPolicy::periodic(60_000))
    .build()
    .unwrap();

assert_eq!(spec.slot().as_str(), "daily-cleanup");
assert_eq!(spec.timeout().as_millis(), 5_000);

Implementations§

Source§

impl TaskSpec

Source

pub fn slot(&self) -> &Slot

Logical slot name for concurrency control.

Source

pub fn workload(&self) -> &TaskWorkload

Workload desired state.

Source

pub fn timeout(&self) -> Timeout

Per-attempt timeout.

Source

pub fn restart(&self) -> RestartPolicy

Restart policy applied after completion or failure.

Source

pub fn backoff(&self) -> &BackoffPolicy

Backoff configuration between restart attempts.

Source

pub fn admission(&self) -> AdmissionPolicy

Admission policy for handling slot conflicts.

Source

pub fn max_retries(&self) -> Option<NonZeroU32>

Maximum consecutive failure retries.

None means unlimited. Zero is not representable.

Source

pub fn runner_selector(&self) -> Option<&LabelSelector>

Label selector for runner routing, if present.

Source§

impl TaskSpec

Source

pub fn builder( slot: impl AsRef<str>, workload: TaskWorkload, timeout: impl Into<u64>, ) -> TaskSpecBuilder

Creates a builder with the required fields.

use solti_model::{TaskSpec, TaskWorkload, SubprocessSpec, SubprocessMode, RestartPolicy};

let spec = TaskSpec::builder(
    "my-slot",
    TaskWorkload::Subprocess(SubprocessSpec::new(
        SubprocessMode::Command {
            command: "echo".into(),
            args: vec!["hello".into()],
        },
        Default::default(),
        None,
        Default::default(),
    )),
    5_000u64,
)
.restart(RestartPolicy::OnFailure)
.build()
.expect("valid spec");
Source§

impl TaskSpec

Source

pub fn with_runner_selector(self, sel: LabelSelector) -> Self

Sets a runner selector on an existing spec.

This method does not validate sel. Call Self::validate before using the result outside a validated resource.

§Example
use solti_model::{EmbeddedSpec, Labels, LabelSelector, TaskSpec, TaskWorkload};

let mut labels = Labels::new();
labels.insert("zone", "eu");

let workload = TaskWorkload::Embedded(EmbeddedSpec::new("v1").unwrap());
let spec = TaskSpec::builder("build", workload, 1_000u64)
    .build()
    .unwrap()
    .with_runner_selector(LabelSelector::from_labels(labels));

assert!(spec.runner_selector().is_some());
Source

pub fn with_admission(self, admission: AdmissionPolicy) -> Self

Sets the admission policy on an existing spec.

§Example
use solti_model::{AdmissionPolicy, EmbeddedSpec, TaskSpec, TaskWorkload};

let workload = TaskWorkload::Embedded(EmbeddedSpec::new("v1").unwrap());
let spec = TaskSpec::builder("agent", workload, 1_000u64)
    .build()
    .unwrap()
    .with_admission(AdmissionPolicy::Replace);

assert_eq!(spec.admission(), AdmissionPolicy::Replace);
Source§

impl TaskSpec

Source

pub fn validate(&self) -> ModelResult<()>

Validates the complete spec.

§Errors

Returns ModelError::Invalid when the slot, workload, backoff, or runner selector is invalid.

§Example
use solti_model::{
    Flag, SubprocessMode, SubprocessSpec, TaskEnv, TaskSpec, TaskWorkload,
};

let spec = TaskSpec::builder(
    "hello",
    TaskWorkload::Subprocess(SubprocessSpec::new(
        SubprocessMode::Command {
            command: "echo".into(),
            args: vec!["hello".into()],
        },
        TaskEnv::default(),
        None,
        Flag::enabled(),
    )),
    1_000u64,
)
.build()
.unwrap();

spec.validate().unwrap();

Trait Implementations§

Source§

impl Clone for TaskSpec

Source§

fn clone(&self) -> TaskSpec

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 Debug for TaskSpec

Source§

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

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

impl<'de> Deserialize<'de> for TaskSpec

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for TaskSpec

Source§

impl JsonSchema for TaskSpec

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for TaskSpec

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for TaskSpec

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for TaskSpec

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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.