redis_enterprise/
actions.rs1use crate::client::RestClient;
9use crate::error::Result;
10use serde::{Deserialize, Serialize};
11use serde_json::Value;
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct Action {
17 pub action_uid: String,
19 pub name: String,
21 pub status: String,
25 pub progress: Option<f32>,
27 pub start_time: Option<String>,
29 pub end_time: Option<String>,
31 pub description: Option<String>,
33 pub error: Option<String>,
35 pub bdb_uid: Option<u32>,
37 pub node_uid: Option<u32>,
39
40 #[serde(flatten)]
41 pub extra: Value,
42}
43
44pub struct ActionHandler {
47 client: RestClient,
48}
49
50impl ActionHandler {
51 pub fn new(client: RestClient) -> Self {
52 ActionHandler { client }
53 }
54
55 pub async fn list(&self) -> Result<Vec<Action>> {
57 self.client.get("/v1/actions").await
58 }
59
60 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 pub async fn cancel(&self, action_uid: &str) -> Result<()> {
69 self.client
70 .delete(&format!("/v1/actions/{}", action_uid))
71 .await
72 }
73
74 pub async fn list_v2(&self) -> Result<Vec<Action>> {
76 self.client.get("/v2/actions").await
77 }
78
79 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 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 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}