1use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ExistsWorkerWithTagError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GeDefaultTagsError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetCountsOfJobsWaitingPerTagError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetCustomTagsError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetQueueMetricsError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum IsDefaultTagsPerWorkspaceError {
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum ListWorkersError {
64 UnknownValue(serde_json::Value),
65}
66
67
68pub async fn exists_worker_with_tag(configuration: &configuration::Configuration, tag: &str) -> Result<bool, Error<ExistsWorkerWithTagError>> {
69 let local_var_configuration = configuration;
70
71 let local_var_client = &local_var_configuration.client;
72
73 let local_var_uri_str = format!("{}/workers/exists_worker_with_tag", local_var_configuration.base_path);
74 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
75
76 local_var_req_builder = local_var_req_builder.query(&[("tag", &tag.to_string())]);
77 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
78 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
79 }
80 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
81 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
82 };
83
84 let local_var_req = local_var_req_builder.build()?;
85 let local_var_resp = local_var_client.execute(local_var_req).await?;
86
87 let local_var_status = local_var_resp.status();
88 let local_var_content = local_var_resp.text().await?;
89
90 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
91 crate::from_str_patched(&local_var_content).map_err(Error::from)
92 } else {
93 let local_var_entity: Option<ExistsWorkerWithTagError> = crate::from_str_patched(&local_var_content).ok();
94 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
95 Err(Error::ResponseError(local_var_error))
96 }
97}
98
99pub async fn ge_default_tags(configuration: &configuration::Configuration, ) -> Result<Vec<String>, Error<GeDefaultTagsError>> {
100 let local_var_configuration = configuration;
101
102 let local_var_client = &local_var_configuration.client;
103
104 let local_var_uri_str = format!("{}/workers/get_default_tags", local_var_configuration.base_path);
105 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
106
107 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
108 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
109 }
110 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
111 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
112 };
113
114 let local_var_req = local_var_req_builder.build()?;
115 let local_var_resp = local_var_client.execute(local_var_req).await?;
116
117 let local_var_status = local_var_resp.status();
118 let local_var_content = local_var_resp.text().await?;
119
120 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
121 crate::from_str_patched(&local_var_content).map_err(Error::from)
122 } else {
123 let local_var_entity: Option<GeDefaultTagsError> = crate::from_str_patched(&local_var_content).ok();
124 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
125 Err(Error::ResponseError(local_var_error))
126 }
127}
128
129pub async fn get_counts_of_jobs_waiting_per_tag(configuration: &configuration::Configuration, ) -> Result<std::collections::HashMap<String, i32>, Error<GetCountsOfJobsWaitingPerTagError>> {
130 let local_var_configuration = configuration;
131
132 let local_var_client = &local_var_configuration.client;
133
134 let local_var_uri_str = format!("{}/workers/queue_counts", local_var_configuration.base_path);
135 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
136
137 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
138 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
139 }
140 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
141 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
142 };
143
144 let local_var_req = local_var_req_builder.build()?;
145 let local_var_resp = local_var_client.execute(local_var_req).await?;
146
147 let local_var_status = local_var_resp.status();
148 let local_var_content = local_var_resp.text().await?;
149
150 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
151 crate::from_str_patched(&local_var_content).map_err(Error::from)
152 } else {
153 let local_var_entity: Option<GetCountsOfJobsWaitingPerTagError> = crate::from_str_patched(&local_var_content).ok();
154 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
155 Err(Error::ResponseError(local_var_error))
156 }
157}
158
159pub async fn get_custom_tags(configuration: &configuration::Configuration, workspace: Option<&str>, show_workspace_restriction: Option<bool>) -> Result<Vec<String>, Error<GetCustomTagsError>> {
160 let local_var_configuration = configuration;
161
162 let local_var_client = &local_var_configuration.client;
163
164 let local_var_uri_str = format!("{}/workers/custom_tags", local_var_configuration.base_path);
165 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
166
167 if let Some(ref local_var_str) = workspace {
168 local_var_req_builder = local_var_req_builder.query(&[("workspace", &local_var_str.to_string())]);
169 }
170 if let Some(ref local_var_str) = show_workspace_restriction {
171 local_var_req_builder = local_var_req_builder.query(&[("show_workspace_restriction", &local_var_str.to_string())]);
172 }
173 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
174 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
175 }
176 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
177 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
178 };
179
180 let local_var_req = local_var_req_builder.build()?;
181 let local_var_resp = local_var_client.execute(local_var_req).await?;
182
183 let local_var_status = local_var_resp.status();
184 let local_var_content = local_var_resp.text().await?;
185
186 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
187 crate::from_str_patched(&local_var_content).map_err(Error::from)
188 } else {
189 let local_var_entity: Option<GetCustomTagsError> = crate::from_str_patched(&local_var_content).ok();
190 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
191 Err(Error::ResponseError(local_var_error))
192 }
193}
194
195pub async fn get_queue_metrics(configuration: &configuration::Configuration, ) -> Result<Vec<models::GetQueueMetrics200ResponseInner>, Error<GetQueueMetricsError>> {
196 let local_var_configuration = configuration;
197
198 let local_var_client = &local_var_configuration.client;
199
200 let local_var_uri_str = format!("{}/workers/queue_metrics", local_var_configuration.base_path);
201 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
202
203 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
204 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
205 }
206 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
207 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
208 };
209
210 let local_var_req = local_var_req_builder.build()?;
211 let local_var_resp = local_var_client.execute(local_var_req).await?;
212
213 let local_var_status = local_var_resp.status();
214 let local_var_content = local_var_resp.text().await?;
215
216 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
217 crate::from_str_patched(&local_var_content).map_err(Error::from)
218 } else {
219 let local_var_entity: Option<GetQueueMetricsError> = crate::from_str_patched(&local_var_content).ok();
220 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
221 Err(Error::ResponseError(local_var_error))
222 }
223}
224
225pub async fn is_default_tags_per_workspace(configuration: &configuration::Configuration, ) -> Result<bool, Error<IsDefaultTagsPerWorkspaceError>> {
226 let local_var_configuration = configuration;
227
228 let local_var_client = &local_var_configuration.client;
229
230 let local_var_uri_str = format!("{}/workers/is_default_tags_per_workspace", local_var_configuration.base_path);
231 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
232
233 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
234 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
235 }
236 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
237 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
238 };
239
240 let local_var_req = local_var_req_builder.build()?;
241 let local_var_resp = local_var_client.execute(local_var_req).await?;
242
243 let local_var_status = local_var_resp.status();
244 let local_var_content = local_var_resp.text().await?;
245
246 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
247 crate::from_str_patched(&local_var_content).map_err(Error::from)
248 } else {
249 let local_var_entity: Option<IsDefaultTagsPerWorkspaceError> = crate::from_str_patched(&local_var_content).ok();
250 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
251 Err(Error::ResponseError(local_var_error))
252 }
253}
254
255pub async fn list_workers(configuration: &configuration::Configuration, page: Option<i32>, per_page: Option<i32>, ping_since: Option<i32>) -> Result<Vec<models::WorkerPing>, Error<ListWorkersError>> {
256 let local_var_configuration = configuration;
257
258 let local_var_client = &local_var_configuration.client;
259
260 let local_var_uri_str = format!("{}/workers/list", local_var_configuration.base_path);
261 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
262
263 if let Some(ref local_var_str) = page {
264 local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
265 }
266 if let Some(ref local_var_str) = per_page {
267 local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
268 }
269 if let Some(ref local_var_str) = ping_since {
270 local_var_req_builder = local_var_req_builder.query(&[("ping_since", &local_var_str.to_string())]);
271 }
272 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
273 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
274 }
275 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
276 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
277 };
278
279 let local_var_req = local_var_req_builder.build()?;
280 let local_var_resp = local_var_client.execute(local_var_req).await?;
281
282 let local_var_status = local_var_resp.status();
283 let local_var_content = local_var_resp.text().await?;
284
285 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
286 crate::from_str_patched(&local_var_content).map_err(Error::from)
287 } else {
288 let local_var_entity: Option<ListWorkersError> = crate::from_str_patched(&local_var_content).ok();
289 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
290 Err(Error::ResponseError(local_var_error))
291 }
292}
293