smelter_job_manager/
lib.rs

1#![warn(missing_docs)]
2#![warn(clippy::missing_docs_in_private_items)]
3
4//! Manage and run jobs for Smelter
5
6use std::{borrow::Cow, fmt::Debug};
7
8use error_stack::Report;
9use serde::de::DeserializeOwned;
10pub use smelter_worker::SubtaskId;
11pub use spawn::{SpawnedTask, TaskError};
12
13mod job;
14mod manager;
15mod run_subtask;
16mod scheduler;
17mod spawn;
18mod stage;
19mod task_status;
20#[cfg(test)]
21mod test_util;
22
23pub use job::*;
24pub use manager::*;
25pub use scheduler::*;
26pub use spawn::*;
27pub use stage::*;
28pub use task_status::*;
29
30/// A task definition, along with the output that resulted from running it.
31#[derive(Debug)]
32pub struct TaskDefWithOutput<DEF: SubTask> {
33    /// The task definition.
34    pub task_def: DEF,
35    /// The output of running the task.
36    pub output: DEF::Output,
37    /// Statistics about the task execution.
38    pub stats: Option<smelter_worker::stats::Statistics>,
39}
40
41/// A definition of a subtask.
42#[async_trait::async_trait]
43pub trait SubTask: Clone + Debug + Send + Sync + 'static {
44    /// The type of output produced by this task.
45    type Output: Debug + DeserializeOwned + Send + 'static;
46
47    /// A name that describes the task.
48    fn description(&self) -> Cow<'static, str>;
49
50    /// Start the task with the appropriate arguments.
51    async fn spawn(
52        &self,
53        task_id: SubtaskId,
54        logs: Option<LogSender>,
55    ) -> Result<Box<dyn SpawnedTask>, Report<TaskError>>;
56}