use std::sync::Arc;
use crate::error::{map_task_schedule_err as map_err, ManagerError};
use crate::gen::task_schedule::apis::configuration::Configuration;
use crate::gen::task_schedule::apis::schedule_manager_api as api;
use crate::gen::task_schedule::models;
use crate::retry::{with_retry, RetryPolicy};
pub struct TaskSchedulesResource {
pub(crate) cfg: Arc<Configuration>,
pub(crate) retry: RetryPolicy,
}
impl TaskSchedulesResource {
pub async fn list(&self) -> Result<models::TaskScheduleList, ManagerError> {
with_retry(&self.retry, true, || {
api::get_task_schedules(self.cfg.as_ref(), None, None)
})
.await
.map_err(map_err)
}
pub async fn create(&self, body: models::SubmitTaskSchedule) -> Result<(), ManagerError> {
with_retry(&self.retry, false, || {
api::submit_task_schedule(self.cfg.as_ref(), body.clone())
})
.await
.map_err(map_err)
}
pub async fn get(&self, name: &str) -> Result<models::TaskSchedule, ManagerError> {
with_retry(&self.retry, true, || {
api::get_task_schedule(self.cfg.as_ref(), name)
})
.await
.map_err(map_err)
}
pub async fn delete(&self, name: &str) -> Result<(), ManagerError> {
with_retry(&self.retry, false, || {
api::delete_schedule_task(self.cfg.as_ref(), name)
})
.await
.map_err(map_err)
}
}