conductor/src/job.rs

67 lines
1.3 KiB
Rust

use actix::Message;
use std::{
collections::HashMap,
ops::{Deref, DerefMut},
};
#[derive(Clone, Message)]
#[rtype(result = "()")]
pub struct Jobs(Vec<Job>);
impl Jobs {
pub fn new(tasks: Vec<Job>) -> Self {
Self(tasks)
}
}
impl std::fmt::Debug for Jobs {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Jobs")
.field(
"list",
&self.iter().map(|j| j.name.clone()).collect::<Vec<_>>(),
)
.finish()
}
}
impl Deref for Jobs {
type Target = Vec<Job>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for Jobs {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
#[derive(Clone, Debug, Message)]
#[rtype(result = "()")]
pub struct Job {
pub name: String,
pub command: String,
pub path: String,
pub env: HashMap<String, String>,
pub retry: bool,
pub keep_alive: bool,
pub retry_delay: u64,
}
impl Default for Job {
fn default() -> Self {
Job {
name: "Unnamed".to_string(),
command: "".to_string(),
path: ".".to_string(),
env: HashMap::new(),
retry: true,
keep_alive: true,
retry_delay: 2,
}
}
}