redis_enterprise/
crdb_tasks.rs

1//! Active-Active database task operations
2//!
3//! ## Overview
4//! - Track CRDB async operations
5//! - Query task status
6//! - Manage replication tasks
7
8use crate::client::RestClient;
9use crate::error::Result;
10use serde::{Deserialize, Serialize};
11use serde_json::Value;
12use typed_builder::TypedBuilder;
13
14/// CRDB task information
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct CrdbTask {
17    /// Unique task identifier
18    pub task_id: String,
19    /// Globally unique Active-Active database ID (GUID)
20    pub crdb_guid: String,
21    /// Type of task being executed
22    pub task_type: String,
23    /// Current status of the task (queued, running, completed, failed)
24    pub status: String,
25    /// Task completion progress as a percentage (0.0-100.0)
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub progress: Option<f32>,
28    /// Timestamp when the task was started (ISO 8601 format)
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub start_time: Option<String>,
31    /// Timestamp when the task was completed or failed (ISO 8601 format)
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub end_time: Option<String>,
34    /// Error description if the task failed
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub error: Option<String>,
37
38    #[serde(flatten)]
39    pub extra: Value,
40}
41
42/// CRDB task creation request
43#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
44pub struct CreateCrdbTaskRequest {
45    /// Globally unique Active-Active database ID (GUID) for the target CRDB
46    #[builder(setter(into))]
47    pub crdb_guid: String,
48    /// Type of task to create (e.g., "flush", "purge", "update_config")
49    #[builder(setter(into))]
50    pub task_type: String,
51    /// Optional parameters specific to the task type
52    #[serde(skip_serializing_if = "Option::is_none")]
53    #[builder(default, setter(strip_option))]
54    pub params: Option<Value>,
55}
56
57/// CRDB tasks handler
58pub struct CrdbTasksHandler {
59    client: RestClient,
60}
61
62impl CrdbTasksHandler {
63    pub fn new(client: RestClient) -> Self {
64        CrdbTasksHandler { client }
65    }
66
67    /// List all CRDB tasks
68    pub async fn list(&self) -> Result<Vec<CrdbTask>> {
69        self.client.get("/v1/crdb_tasks").await
70    }
71
72    /// Get specific CRDB task
73    pub async fn get(&self, task_id: &str) -> Result<CrdbTask> {
74        self.client
75            .get(&format!("/v1/crdb_tasks/{}", task_id))
76            .await
77    }
78
79    /// Create a new CRDB task
80    pub async fn create(&self, request: CreateCrdbTaskRequest) -> Result<CrdbTask> {
81        self.client.post("/v1/crdb_tasks", &request).await
82    }
83
84    /// Cancel a CRDB task
85    pub async fn cancel(&self, task_id: &str) -> Result<()> {
86        self.client
87            .delete(&format!("/v1/crdb_tasks/{}", task_id))
88            .await
89    }
90
91    /// Get tasks for a specific CRDB
92    pub async fn list_by_crdb(&self, crdb_guid: &str) -> Result<Vec<CrdbTask>> {
93        self.client
94            .get(&format!("/v1/crdbs/{}/tasks", crdb_guid))
95            .await
96    }
97}