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. Add watch() before the terminal operation to observe rejection or the final task outcome. Use the default unwatched operation 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. 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 the registry owns it. Cleanup of a force-aborted task can also retain the name. 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

Controller 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

Busy-slot admission policy.

Source

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

Busy-slot policy replacement that preserves the task and slot.

Source

pub fn task_spec(&self) -> &TaskSpec

Borrowed runtime task specification.

Source

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

Runtime task-spec replacement that preserves any explicit slot.

Without one, slot_name uses the name of the new task.

Source

pub fn into_task_spec(self) -> TaskSpec

Runtime task specification without controller settings.

Pass this value to SupervisorHandle::add to bypass slot admission.

Source

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

Explicit admission key separate from the 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

Task-name admission with no explicit slot override.

Source

pub fn slot_name(&self) -> &str

Effective admission key from the explicit slot or task name.

Source

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

Explicit slot override when configured.

Source

pub fn queue(task_spec: TaskSpec) -> Self

FIFO admission 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

Newest-head admission 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

Idle-only admission for incoming work.

A busy slot rejects the request without starting its task body. Add watch() to the submission operation 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) -> Self

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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