redis_enterprise/
crdb_tasks.rs1use crate::client::RestClient;
9use crate::error::Result;
10use serde::{Deserialize, Serialize};
11use serde_json::Value;
12use typed_builder::TypedBuilder;
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct CrdbTask {
17 pub task_id: String,
19 pub crdb_guid: String,
21 pub task_type: String,
23 pub status: String,
25 #[serde(skip_serializing_if = "Option::is_none")]
27 pub progress: Option<f32>,
28 #[serde(skip_serializing_if = "Option::is_none")]
30 pub start_time: Option<String>,
31 #[serde(skip_serializing_if = "Option::is_none")]
33 pub end_time: Option<String>,
34 #[serde(skip_serializing_if = "Option::is_none")]
36 pub error: Option<String>,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
41pub struct CreateCrdbTaskRequest {
42 #[builder(setter(into))]
44 pub crdb_guid: String,
45 #[builder(setter(into))]
47 pub task_type: String,
48 #[serde(skip_serializing_if = "Option::is_none")]
50 #[builder(default, setter(strip_option))]
51 pub params: Option<Value>,
52}
53
54pub struct CrdbTasksHandler {
56 client: RestClient,
57}
58
59impl CrdbTasksHandler {
60 pub fn new(client: RestClient) -> Self {
62 CrdbTasksHandler { client }
63 }
64
65 pub async fn list(&self) -> Result<Vec<CrdbTask>> {
67 self.client.get("/v1/crdb_tasks").await
68 }
69
70 pub async fn get(&self, task_id: &str) -> Result<CrdbTask> {
72 self.client
73 .get(&format!("/v1/crdb_tasks/{}", task_id))
74 .await
75 }
76
77 pub async fn create(&self, request: CreateCrdbTaskRequest) -> Result<CrdbTask> {
79 self.client.post("/v1/crdb_tasks", &request).await
80 }
81
82 pub async fn cancel(&self, task_id: &str) -> Result<()> {
84 self.client
85 .post_action(
86 &format!("/v1/crdb_tasks/{}/actions/cancel", task_id),
87 &serde_json::json!({}),
88 )
89 .await
90 }
91
92 pub async fn cancel_with_force(&self, task_id: &str, force: bool) -> Result<()> {
94 let path = if force {
95 format!("/v1/crdb_tasks/{}/actions/cancel?force=true", task_id)
96 } else {
97 format!("/v1/crdb_tasks/{}/actions/cancel", task_id)
98 };
99
100 self.client.post_action(&path, &serde_json::json!({})).await
101 }
102
103 pub async fn list_by_crdb(&self, crdb_guid: &str) -> Result<Vec<CrdbTask>> {
105 self.client
106 .get(&format!("/v1/crdbs/{}/tasks", crdb_guid))
107 .await
108 }
109}