Skip to main content

llmrix_rust_sdk/resources/
cron.rs

1use std::sync::Arc;
2use crate::{error::Result, model::*, transport::*};
3
4/// Operations on the Cron Tasks API. Obtain via [`LlmrixClient::cron`].
5pub struct CronResource {
6    pub(crate) t: Arc<Transport>,
7}
8
9impl CronResource {
10    /// Return all cron tasks.
11    pub async fn list(&self) -> Result<Vec<CronTask>> {
12        self.t.get_unwrap(&path_cron_tasks(), "tasks").await
13    }
14
15    /// Create a new cron task.
16    pub async fn create(&self, req: CronCreateRequest) -> Result<CronTask> {
17        self.t.post(&path_cron_tasks(), &req).await
18    }
19
20    /// Retrieve a single cron task by its UUID.
21    pub async fn get(&self, task_id: &str) -> Result<CronTask> {
22        self.t.get(&path_cron_task(task_id)).await
23    }
24
25    /// Update a cron task's properties.
26    pub async fn update(&self, task_id: &str, req: CronUpdateRequest) -> Result<CronTask> {
27        self.t.put(&path_cron_task(task_id), &req).await
28    }
29
30    /// Pause an active cron task.
31    pub async fn pause(&self, task_id: &str) -> Result<CronTask> {
32        self.t.post(&path_cron_pause(task_id), &serde_json::Value::Object(Default::default())).await
33    }
34
35    /// Resume a paused cron task.
36    pub async fn resume(&self, task_id: &str) -> Result<CronTask> {
37        self.t.post(&path_cron_resume(task_id), &serde_json::Value::Object(Default::default())).await
38    }
39
40    /// Permanently delete a cron task.
41    pub async fn delete(&self, task_id: &str) -> Result<()> {
42        self.t.delete(&path_cron_task(task_id)).await
43    }
44}