Skip to main content

ControllerSpec

Struct ControllerSpec 

Source
pub struct ControllerSpec { /* private fields */ }
Available on crate feature controller only.
Expand description

A task, admission slot, and busy-slot policy submitted as one request.

The contained TaskSpec defines how the task runs after registry admission. The controller settings define when it may enter the registry:

  • an AdmissionPolicy for a busy slot;
  • an optional slot that groups work which must not overlap.

Pass the request to SupervisorHandle::submit_and_watch when application logic needs to know whether work was rejected or how an admitted task ended. Use SupervisorHandle::submit when command intake alone is enough. Allocate its task ID before intake with SupervisorHandle::prepare_submission.

§Admission flow

application
     │ ControllerSpec
     ▼
SupervisorHandle::submit*
     ▼
controller command queue
     ▼
controller slot
     ├── idle ──► TaskSpec ──► runtime registry ──► managed task
     └── busy ──► apply AdmissionPolicy

§Task name and slot

A task name is a unique registry key and diagnostic label. A slot groups work for controller admission. Different task names can share a slot. Without an explicit slot, the task name is used for both roles.

Slots do not create a second task namespace. A task name stays reserved while it belongs to the registry or to Taskvisor’s cleanup of a force-aborted task. The name can be admitted again after that ownership ends.

§Examples

use taskvisor::{AdmissionPolicy, ControllerSpec, TaskFn, TaskRef, TaskSpec};

let task: TaskRef = TaskFn::arc(|_ctx| async {
    Ok(())
});

let request = ControllerSpec::queue(TaskSpec::once("deploy-main-42", task))
    .with_slot("deploy-main");

assert_eq!(request.admission(), AdmissionPolicy::Queue);
assert_eq!(request.task_spec().name(), "deploy-main-42");
assert_eq!(request.slot_name(), "deploy-main");

Implementations§

Source§

impl ControllerSpec

Source

pub fn new(admission: AdmissionPolicy, task_spec: TaskSpec) -> Self

Creates a request from an explicit policy and task specification.

The task name is the effective slot until with_slot sets a separate key. Prefer queue, replace, or drop_if_running when the policy is known at the call site.

Source

pub fn admission(&self) -> AdmissionPolicy

Returns the admission policy.

Source

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

Replaces the busy-slot policy without changing the task or slot.

Source

pub fn task_spec(&self) -> &TaskSpec

Returns the contained task specification.

Source

pub fn with_task_spec(self, task_spec: TaskSpec) -> Self

Replaces the contained task specification.

An explicit slot stays unchanged. Without one, slot_name uses the name of the new task.

Source

pub fn into_task_spec(self) -> TaskSpec

Removes controller settings and returns the runtime task specification.

The returned value can be passed to a direct add* method when the caller decides to bypass slot admission.

Source

pub fn with_slot(self, slot: impl Into<Arc<str>>) -> Self

Groups this task under an admission key separate from its task name.

Tasks with the same effective slot cannot own that slot together. The task name remains unchanged and is still checked by the runtime registry.

Source

pub fn without_slot(self) -> Self

Clears the slot override and groups this request by task name again.

Source

pub fn slot_name(&self) -> &str

Returns the effective slot: the explicit slot or the task name.

Source

pub fn slot_override(&self) -> Option<&str>

Returns the explicit slot override, or None when task name is the slot.

Source

pub fn queue(task_spec: TaskSpec) -> Self

Creates a request that queues behind older work in a busy slot.

Use this when incoming work should join the FIFO order. Queue limits can still reject the submission after command intake. See AdmissionPolicy::Queue for the full contract.

Source

pub fn replace(task_spec: TaskSpec) -> Self

Creates a request that becomes the newest queue head in a busy slot.

Use this when the next item should carry the newest value. This retires the current owner but does not clear older FIFO entries behind the head. See AdmissionPolicy::Replace for the full contract.

Source

pub fn drop_if_running(task_spec: TaskSpec) -> Self

Creates a request that runs only when the slot is idle.

A busy slot rejects the request without starting its task body. Use a watched submit method when the caller must observe that decision. See AdmissionPolicy::DropIfRunning for the full contract.

Trait Implementations§

Source§

impl Clone for ControllerSpec

Source§

fn clone(&self) -> ControllerSpec

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 ControllerSpec

Source§

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

Formats the value using the given formatter. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more