use crate::{
models::{AddCronJob, CronJob, EditCronJob},
CpanelClient, CpanelError,
};
impl CpanelClient {
pub async fn list_cron_jobs(&self, user: &str) -> Result<Vec<CronJob>, CpanelError> {
let result: Vec<CronJob> = self
.uapi("Cron", "list_cron_jobs", &[("user", user)])
.await?;
Ok(result)
}
pub async fn add_cron_job(&self, user: &str, job: &AddCronJob) -> Result<(), CpanelError> {
let params: Vec<(&str, &str)> = vec![
("user", user),
("minute", &job.minute),
("hour", &job.hour),
("day", &job.day),
("month", &job.month),
("weekday", &job.weekday),
("command", &job.command),
];
let _: () = self.uapi("Cron", "add_cron_job", ¶ms).await?;
Ok(())
}
pub async fn edit_cron_job(&self, user: &str, edit: &EditCronJob) -> Result<(), CpanelError> {
let mut params: Vec<(&str, &str)> = vec![("user", user), ("job", &edit.job)];
if let Some(ref s) = edit.minute {
params.push(("minute", s));
}
if let Some(ref s) = edit.hour {
params.push(("hour", s));
}
if let Some(ref s) = edit.day {
params.push(("day", s));
}
if let Some(ref s) = edit.month {
params.push(("month", s));
}
if let Some(ref s) = edit.weekday {
params.push(("weekday", s));
}
if let Some(ref s) = edit.command {
params.push(("command", s));
}
if let Some(ref s) = edit.email {
params.push(("email", s));
}
let _: () = self.uapi("Cron", "edit_cron_job", ¶ms).await?;
Ok(())
}
pub async fn delete_cron_job(&self, user: &str, job_id: &str) -> Result<(), CpanelError> {
let _: () = self
.uapi(
"Cron",
"delete_cron_job",
&[("user", user), ("job", job_id)],
)
.await?;
Ok(())
}
}