Skip to main content

romm_api/client/
tasks.rs

1use serde_json::Value;
2
3use crate::error::ApiError;
4
5use super::RommClient;
6
7impl RommClient {
8    /// Triggers a server-side task by name (e.g., `"scan_library"`).
9    pub async fn run_task(
10        &self,
11        task_name: &str,
12        kwargs: Option<Value>,
13    ) -> Result<Value, ApiError> {
14        let path = format!("/api/tasks/run/{}", task_name);
15        self.request_json("POST", &path, &[], kwargs).await
16    }
17
18    /// Polls the status of a running task by its ID.
19    pub async fn get_task_status(&self, task_id: &str) -> Result<Value, ApiError> {
20        let path = format!("/api/tasks/{}", task_id);
21        self.request_json("GET", &path, &[], None).await
22    }
23
24    /// Enqueues all runnable tasks on the server.
25    pub async fn run_all_tasks(&self) -> Result<Value, ApiError> {
26        self.request_json("POST", "/api/tasks/run", &[], None).await
27    }
28
29    /// Lists all recent and active tasks.
30    pub async fn list_tasks(&self) -> Result<Value, ApiError> {
31        self.request_json("GET", "/api/tasks", &[], None).await
32    }
33
34    /// Returns the current status of the task queue.
35    pub async fn get_tasks_queue_status(&self) -> Result<Value, ApiError> {
36        self.request_json("GET", "/api/tasks/status", &[], None)
37            .await
38    }
39}