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
CoreErrorerror type returned by all methods.StateConfigconfigures sweep TTLs and interval (defaults are sane).solti_runner::RunnerRouterpicks a runner for each submitted spec.
Implementations§
Source§impl SupervisorApi
impl SupervisorApi
Sourcepub async fn new(
sup_cfg: SupervisorConfig,
ctrl_cfg: ControllerConfig,
subscribers: Vec<Arc<dyn Subscribe>>,
router: RunnerRouter,
state_cfg: StateConfig,
) -> Result<Self, CoreError>
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 routersolti_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.
Sourcepub fn list_tasks_by_slot(&self, slot: &str) -> Vec<Task>
pub fn list_tasks_by_slot(&self, slot: &str) -> Vec<Task>
List all tasks in a specific slot.
Sourcepub fn list_all_tasks(&self) -> Vec<Task>
pub fn list_all_tasks(&self) -> Vec<Task>
List all tasks.
Sourcepub fn list_tasks_by_status(&self, phase: TaskPhase) -> Vec<Task>
pub fn list_tasks_by_status(&self, phase: TaskPhase) -> Vec<Task>
List tasks by phase.
Sourcepub fn query_tasks(&self, query: &TaskQuery) -> TaskPage<Task>
pub fn query_tasks(&self, query: &TaskQuery) -> TaskPage<Task>
Query tasks with combined filters and pagination.
Sourcepub fn list_task_runs(&self, id: &TaskId) -> Vec<TaskRun>
pub fn list_task_runs(&self, id: &TaskId) -> Vec<TaskRun>
List execution history for a specific task (oldest first).
Sourcepub async fn delete_task(&self, id: &TaskId) -> Result<(), CoreError>
pub async fn delete_task(&self, id: &TaskId) -> Result<(), CoreError>
Stop a task and purge its run history.
Sourcepub fn handle(&self) -> SupervisorHandle
pub fn handle(&self) -> SupervisorHandle
Get a clone of the underlying supervisor handle.
Sourcepub async fn submit(&self, spec: &TaskSpec) -> Result<TaskId, CoreError>
pub async fn submit(&self, spec: &TaskSpec) -> Result<TaskId, CoreError>
Build and submit a task described by TaskSpec.
Steps:
- Ask the
RunnerRouterto pick a runner and build aTaskRef. - Delegate to
SupervisorApi::submit_with_task.
This is the primary entrypoint for tasks that are fully described by the public solti_model::TaskKind model.
Sourcepub async fn submit_with_task(
&self,
task: TaskRef,
spec: &TaskSpec,
) -> Result<TaskId, CoreError>
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.
Sourcepub async fn shutdown(self) -> Result<(), CoreError>
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?;