Skip to main content

TaskSpecBuilder

Struct TaskSpecBuilder 

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

Builder for TaskSpec.

Required fields are set by TaskSpec::builder.

Optional fields use these defaults:

§Example

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

let workload = TaskWorkload::Embedded(EmbeddedSpec::new("v1").unwrap());
let spec = TaskSpec::builder("service", workload, 5_000u64)
    .restart(RestartPolicy::always())
    .admission(AdmissionPolicy::Replace)
    .build()
    .unwrap();

assert_eq!(spec.restart(), RestartPolicy::always());
assert_eq!(spec.admission(), AdmissionPolicy::Replace);

Implementations§

Source§

impl TaskSpecBuilder

Source

pub fn restart(self, restart: RestartPolicy) -> Self

Sets the restart policy.

Source

pub fn max_retries(self, max_retries: impl Into<Option<NonZeroU32>>) -> Self

Sets the failure-retry budget.

None means unlimited.

let workload = TaskWorkload::Embedded(EmbeddedSpec::new("v1").unwrap());
let spec = TaskSpec::builder("s", workload, 1_000u64)
    .max_retries(NonZeroU32::new(3))
    .build()
    .expect("valid spec");
assert_eq!(spec.max_retries().map(NonZeroU32::get), Some(3));
Source

pub fn backoff(self, backoff: BackoffPolicy) -> Self

Sets the backoff policy.

Source

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

Sets the admission policy.

Source

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

Sets the runner selector.

Source

pub fn build(self) -> ModelResult<TaskSpec>

Builds and validates the spec.

Runner availability is not checked by this crate.

§Errors

Returns ModelError::Invalid when any structural field is invalid.

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

let workload = TaskWorkload::Embedded(EmbeddedSpec::new("v1").unwrap());
let err = TaskSpec::builder("", workload, 1_000u64)
    .build()
    .unwrap_err();

assert!(err.to_string().contains("slot"));

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