Skip to main content

SupervisorApi

Struct SupervisorApi 

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

Thin wrapper around taskvisor Supervisor with a runner router.

This type is responsible for:

  • constructing and running the supervisor;
  • selecting a concrete runner for each TaskSpec;
  • mapping model-level specs into controller specs and submitting them.

§Also

Implementations§

Source§

impl SupervisorApi

Source

pub async fn new( sup_cfg: SupervisorConfig, ctrl_cfg: ControllerConfig, subscribers: Vec<Arc<dyn Subscribe>>, router: RunnerRouter, state_cfg: StateConfig, ) -> Result<Self, CoreError>

Create a supervisor with explicit configs and start its run loop in the background.

  • sup_cfg - supervisor configuration;
  • ctrl_cfg - controller configuration;
  • subscribers - event subscribers to attach to the supervisor;
  • router - runner router solti_model::TaskKind;
  • state_cfg - sweep TTLs and interval (StateConfig::default() is usually fine).

The supervisor event loop is started via Supervisor::serve() which returns a SupervisorHandle for dynamic task management.

A periodic sweep task is automatically submitted to prevent unbounded memory growth. It removes completed runs and terminal tasks that exceed their configured TTLs.

Source

pub fn get_task(&self, id: &TaskId) -> Option<Task>

Get task information by ID.

Source

pub fn list_tasks_by_slot(&self, slot: &str) -> Vec<Task>

List all tasks in a specific slot.

Source

pub fn list_all_tasks(&self) -> Vec<Task>

List all tasks.

Source

pub fn list_tasks_by_status(&self, phase: TaskPhase) -> Vec<Task>

List tasks by phase.

Source

pub fn query_tasks(&self, query: &TaskQuery) -> TaskPage<Task>

Query tasks with combined filters and pagination.

Source

pub fn list_task_runs(&self, id: &TaskId) -> Vec<TaskRun>

List execution history for a specific task (oldest first).

Source

pub async fn delete_task(&self, id: &TaskId) -> Result<(), CoreError>

Stop a task and purge its run history.

Source

pub fn handle(&self) -> SupervisorHandle

Get a clone of the underlying supervisor handle.

Source

pub async fn submit(&self, spec: &TaskSpec) -> Result<TaskId, CoreError>

Build and submit a task described by TaskSpec.

Steps:

  1. Ask the RunnerRouter to pick a runner and build a TaskRef.
  2. Delegate to SupervisorApi::submit_with_task.

This is the primary entrypoint for tasks that are fully described by the public solti_model::TaskKind model.

Source

pub async fn submit_with_task( &self, task: TaskRef, spec: &TaskSpec, ) -> Result<TaskId, CoreError>

Submit a pre-built task together with its spec.

This API is intended for in-process / code-defined tasks (with TaskKind::Embedded).

The caller is responsible for constructing the TaskRef; the spec controls timeout, restart, backoff and admission behavior.

Source

pub async fn shutdown(self) -> Result<(), CoreError>

Gracefully shut down the supervisor: cancel all tasks and wait for completion.

Consumes self - no further operations are possible after shutdown. The grace period is determined by SupervisorConfig passed to new.

§Example
api.shutdown().await?;
Source

pub async fn cancel_task(&self, id: &TaskId) -> Result<(), CoreError>

Cancel a running task by ID (in-process Rust API).

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