Skip to main content

solti_runner/
runner.rs

1//! # Runner trait.
2//!
3//! [`Runner`] is the plugin interface for task executors.
4//! Concrete runners implement this trait and are registered in the [`RunnerRouter`](crate::RunnerRouter).
5//!
6//! See the [crate root](crate) for architecture overview and routing rules.
7
8use solti_model::TaskSpec;
9use taskvisor::TaskRef;
10
11use crate::context::BuildContext;
12use crate::error::RunnerError;
13use crate::id::{RunId, make_run_id};
14
15/// Generic task runner used by the core layer.
16///
17/// A runner is responsible for:
18/// - deciding whether it can handle a given [`TaskSpec`] (`supports`)
19/// - building a concrete [`TaskRef`] that the supervisor can execute (`build_task`)
20///
21/// ## Also
22///
23/// - [`RunnerRouter`](crate::RunnerRouter) selects a runner for a given spec.
24/// - [`BuildContext`](crate::BuildContext) shared dependencies passed to [`build_task`](Self::build_task).
25/// - [`RunId`](crate::RunId) is a default id format produced by [`build_run_id`](Self::build_run_id).
26pub trait Runner: Send + Sync {
27    /// Runner name used in logs and diagnostics.
28    fn name(&self) -> &'static str;
29
30    /// Returns `true` if this runner can handle the given spec.
31    fn supports(&self, spec: &TaskSpec) -> bool;
32
33    /// Build a concrete [`TaskRef`] for the given spec.
34    ///
35    /// The provided [`BuildContext`] carries shared dependencies injected at router setup time.
36    /// Slot is extracted from `spec.slot`.
37    fn build_task(&self, spec: &TaskSpec, ctx: &BuildContext) -> Result<TaskRef, RunnerError>;
38
39    /// Builds a default run id for a given slot.
40    ///
41    /// Runners may override this if they need custom id format, otherwise the core helper is used.
42    fn build_run_id(&self, slot: &str) -> RunId {
43        make_run_id(self.name(), slot)
44    }
45}