use std::fmt::{Debug, Display, Formatter};
use anyhow::Error;
use croner::Cron;
#[derive(Clone)]
pub struct ExecJobInfo {
pub name: String,
pub schedule: Cron,
pub command: String,
pub container: String,
pub user: Option<String>,
pub tty: bool,
pub environment: Vec<String>,
}
impl ExecJobInfo {
pub const LABEL: &'static str = "job-exec";
pub async fn exec(self) -> Result<Option<bool>, Error> {
Err(Error::msg("message")) }
pub fn get_schedule(&self) -> Cron {
self.schedule.clone()
}
pub fn may_run_parallel(&self) -> bool {
true
}
}
impl Default for ExecJobInfo {
fn default() -> Self {
Self {
name: Default::default(),
schedule: Cron::new("@hourly").parse().unwrap(),
command: Default::default(),
container: Default::default(),
user: None,
tty: false,
environment: Default::default(),
}
}
}
impl Display for ExecJobInfo {
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
write!(
fmt,
"{}.{}.{}",
Self::LABEL,
self.name,
self.container,
)
}
}
impl Debug for ExecJobInfo {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ExecJobInfo")
.field("name", &self.name)
.field("schedule", &self.schedule.pattern.to_string())
.field("command", &self.command)
.field("container", &self.container)
.field("user", &self.user)
.field("tty", &self.tty)
.field("environment", &self.environment)
.finish()
}
}