redis_enterprise/
actions.rs

1//! Action management for Redis Enterprise async operations
2//!
3//! ## Overview
4//! - Track long-running operations
5//! - Query action status
6//! - Cancel or wait for actions
7
8use crate::client::RestClient;
9use crate::error::Result;
10use serde::{Deserialize, Serialize};
11use serde_json::Value;
12
13/// Action information
14/// Represents an action (operation) in the cluster
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct Action {
17    /// Action's unique identifier (read-only)
18    pub action_uid: String,
19    /// Action's name (read-only)
20    pub name: String,
21    /// Current status of the action
22    ///
23    /// Possible values: 'queued', 'starting', 'running', 'cancelling', 'cancelled', 'completed', 'failed'
24    pub status: String,
25    /// Percent of completed steps in current action (0-100)
26    pub progress: Option<f32>,
27    /// ISO 8601 timestamp when the action was started
28    pub start_time: Option<String>,
29    /// ISO 8601 timestamp when the action completed or failed
30    pub end_time: Option<String>,
31    /// Human-readable description of the action
32    pub description: Option<String>,
33    /// Error message if the action failed
34    pub error: Option<String>,
35    /// Database UID associated with the action
36    pub bdb_uid: Option<u32>,
37    /// Node UID associated with the action
38    pub node_uid: Option<u32>,
39
40    #[serde(flatten)]
41    pub extra: Value,
42}
43
44/// Action handler for tracking async operations
45/// Handler for action-related operations
46pub struct ActionHandler {
47    client: RestClient,
48}
49
50impl ActionHandler {
51    pub fn new(client: RestClient) -> Self {
52        ActionHandler { client }
53    }
54
55    /// List all actions
56    pub async fn list(&self) -> Result<Vec<Action>> {
57        self.client.get("/v1/actions").await
58    }
59
60    /// Get specific action status
61    pub async fn get(&self, action_uid: &str) -> Result<Action> {
62        self.client
63            .get(&format!("/v1/actions/{}", action_uid))
64            .await
65    }
66
67    /// Cancel an action
68    pub async fn cancel(&self, action_uid: &str) -> Result<()> {
69        self.client
70            .delete(&format!("/v1/actions/{}", action_uid))
71            .await
72    }
73
74    /// List actions via v2 API - GET /v2/actions
75    pub async fn list_v2(&self) -> Result<Vec<Action>> {
76        self.client.get("/v2/actions").await
77    }
78
79    /// Get action via v2 API - GET /v2/actions/{uid}
80    pub async fn get_v2(&self, action_uid: &str) -> Result<Action> {
81        self.client
82            .get(&format!("/v2/actions/{}", action_uid))
83            .await
84    }
85
86    /// List actions for a database - GET /v1/actions/bdb/{uid}
87    pub async fn list_for_bdb(&self, bdb_uid: u32) -> Result<Vec<Action>> {
88        self.client
89            .get(&format!("/v1/actions/bdb/{}", bdb_uid))
90            .await
91    }
92
93    // Versioned sub-handlers for clearer API
94    pub fn v1(&self) -> v1::ActionsV1 {
95        v1::ActionsV1::new(self.client.clone())
96    }
97
98    pub fn v2(&self) -> v2::ActionsV2 {
99        v2::ActionsV2::new(self.client.clone())
100    }
101}
102
103pub mod v1 {
104    use super::{Action, RestClient};
105    use crate::error::Result;
106
107    pub struct ActionsV1 {
108        client: RestClient,
109    }
110
111    impl ActionsV1 {
112        pub(crate) fn new(client: RestClient) -> Self {
113            Self { client }
114        }
115
116        pub async fn list(&self) -> Result<Vec<Action>> {
117            self.client.get("/v1/actions").await
118        }
119
120        pub async fn get(&self, action_uid: &str) -> Result<Action> {
121            self.client
122                .get(&format!("/v1/actions/{}", action_uid))
123                .await
124        }
125
126        pub async fn cancel(&self, action_uid: &str) -> Result<()> {
127            self.client
128                .delete(&format!("/v1/actions/{}", action_uid))
129                .await
130        }
131
132        pub async fn list_for_bdb(&self, bdb_uid: u32) -> Result<Vec<Action>> {
133            self.client
134                .get(&format!("/v1/actions/bdb/{}", bdb_uid))
135                .await
136        }
137    }
138}
139
140pub mod v2 {
141    use super::{Action, RestClient};
142    use crate::error::Result;
143
144    pub struct ActionsV2 {
145        client: RestClient,
146    }
147
148    impl ActionsV2 {
149        pub(crate) fn new(client: RestClient) -> Self {
150            Self { client }
151        }
152
153        pub async fn list(&self) -> Result<Vec<Action>> {
154            self.client.get("/v2/actions").await
155        }
156
157        pub async fn get(&self, action_uid: &str) -> Result<Action> {
158            self.client
159                .get(&format!("/v2/actions/{}", action_uid))
160                .await
161        }
162    }
163}