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 ExistsWorkersWithTagsError {
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 GetCountsOfRunningJobsPerTagError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetCustomTagsError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetCustomTagsForWorkspaceError {
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetQueueMetricsError {
64 UnknownValue(serde_json::Value),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum IsDefaultTagsPerWorkspaceError {
71 UnknownValue(serde_json::Value),
72}
73
74#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ListWorkersError {
78 UnknownValue(serde_json::Value),
79}
80
81
82pub async fn exists_workers_with_tags(configuration: &configuration::Configuration, tags: &str, workspace: Option<&str>) -> Result<std::collections::HashMap<String, bool>, Error<ExistsWorkersWithTagsError>> {
83 let local_var_configuration = configuration;
84
85 let local_var_client = &local_var_configuration.client;
86
87 let local_var_uri_str = format!("{}/workers/exists_workers_with_tags", local_var_configuration.base_path);
88 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
89
90 local_var_req_builder = local_var_req_builder.query(&[("tags", &tags.to_string())]);
91 if let Some(ref local_var_str) = workspace {
92 local_var_req_builder = local_var_req_builder.query(&[("workspace", &local_var_str.to_string())]);
93 }
94 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
95 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
96 }
97 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
98 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
99 };
100
101 let local_var_req = local_var_req_builder.build()?;
102 let local_var_resp = local_var_client.execute(local_var_req).await?;
103
104 let local_var_status = local_var_resp.status();
105 let local_var_content = local_var_resp.text().await?;
106
107 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
108 crate::from_str_patched(&local_var_content).map_err(Error::from)
109 } else {
110 let local_var_entity: Option<ExistsWorkersWithTagsError> = crate::from_str_patched(&local_var_content).ok();
111 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
112 Err(Error::ResponseError(local_var_error))
113 }
114}
115
116pub async fn ge_default_tags(configuration: &configuration::Configuration, ) -> Result<Vec<String>, Error<GeDefaultTagsError>> {
117 let local_var_configuration = configuration;
118
119 let local_var_client = &local_var_configuration.client;
120
121 let local_var_uri_str = format!("{}/workers/get_default_tags", local_var_configuration.base_path);
122 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
123
124 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
125 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
126 }
127 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
128 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
129 };
130
131 let local_var_req = local_var_req_builder.build()?;
132 let local_var_resp = local_var_client.execute(local_var_req).await?;
133
134 let local_var_status = local_var_resp.status();
135 let local_var_content = local_var_resp.text().await?;
136
137 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
138 crate::from_str_patched(&local_var_content).map_err(Error::from)
139 } else {
140 let local_var_entity: Option<GeDefaultTagsError> = crate::from_str_patched(&local_var_content).ok();
141 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
142 Err(Error::ResponseError(local_var_error))
143 }
144}
145
146pub async fn get_counts_of_jobs_waiting_per_tag(configuration: &configuration::Configuration, ) -> Result<std::collections::HashMap<String, i32>, Error<GetCountsOfJobsWaitingPerTagError>> {
147 let local_var_configuration = configuration;
148
149 let local_var_client = &local_var_configuration.client;
150
151 let local_var_uri_str = format!("{}/workers/queue_counts", local_var_configuration.base_path);
152 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
153
154 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
155 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
156 }
157 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
158 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
159 };
160
161 let local_var_req = local_var_req_builder.build()?;
162 let local_var_resp = local_var_client.execute(local_var_req).await?;
163
164 let local_var_status = local_var_resp.status();
165 let local_var_content = local_var_resp.text().await?;
166
167 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
168 crate::from_str_patched(&local_var_content).map_err(Error::from)
169 } else {
170 let local_var_entity: Option<GetCountsOfJobsWaitingPerTagError> = crate::from_str_patched(&local_var_content).ok();
171 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
172 Err(Error::ResponseError(local_var_error))
173 }
174}
175
176pub async fn get_counts_of_running_jobs_per_tag(configuration: &configuration::Configuration, ) -> Result<std::collections::HashMap<String, i32>, Error<GetCountsOfRunningJobsPerTagError>> {
177 let local_var_configuration = configuration;
178
179 let local_var_client = &local_var_configuration.client;
180
181 let local_var_uri_str = format!("{}/workers/queue_running_counts", local_var_configuration.base_path);
182 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
183
184 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
185 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
186 }
187 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
188 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
189 };
190
191 let local_var_req = local_var_req_builder.build()?;
192 let local_var_resp = local_var_client.execute(local_var_req).await?;
193
194 let local_var_status = local_var_resp.status();
195 let local_var_content = local_var_resp.text().await?;
196
197 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
198 crate::from_str_patched(&local_var_content).map_err(Error::from)
199 } else {
200 let local_var_entity: Option<GetCountsOfRunningJobsPerTagError> = crate::from_str_patched(&local_var_content).ok();
201 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
202 Err(Error::ResponseError(local_var_error))
203 }
204}
205
206pub async fn get_custom_tags(configuration: &configuration::Configuration, show_workspace_restriction: Option<bool>) -> Result<Vec<String>, Error<GetCustomTagsError>> {
207 let local_var_configuration = configuration;
208
209 let local_var_client = &local_var_configuration.client;
210
211 let local_var_uri_str = format!("{}/workers/custom_tags", local_var_configuration.base_path);
212 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
213
214 if let Some(ref local_var_str) = show_workspace_restriction {
215 local_var_req_builder = local_var_req_builder.query(&[("show_workspace_restriction", &local_var_str.to_string())]);
216 }
217 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
218 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
219 }
220 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
221 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
222 };
223
224 let local_var_req = local_var_req_builder.build()?;
225 let local_var_resp = local_var_client.execute(local_var_req).await?;
226
227 let local_var_status = local_var_resp.status();
228 let local_var_content = local_var_resp.text().await?;
229
230 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
231 crate::from_str_patched(&local_var_content).map_err(Error::from)
232 } else {
233 let local_var_entity: Option<GetCustomTagsError> = crate::from_str_patched(&local_var_content).ok();
234 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
235 Err(Error::ResponseError(local_var_error))
236 }
237}
238
239pub async fn get_custom_tags_for_workspace(configuration: &configuration::Configuration, workspace: &str) -> Result<Vec<String>, Error<GetCustomTagsForWorkspaceError>> {
240 let local_var_configuration = configuration;
241
242 let local_var_client = &local_var_configuration.client;
243
244 let local_var_uri_str = format!("{}/w/{workspace}/workers/custom_tags", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
245 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
246
247 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
248 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
249 }
250 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
251 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
252 };
253
254 let local_var_req = local_var_req_builder.build()?;
255 let local_var_resp = local_var_client.execute(local_var_req).await?;
256
257 let local_var_status = local_var_resp.status();
258 let local_var_content = local_var_resp.text().await?;
259
260 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
261 crate::from_str_patched(&local_var_content).map_err(Error::from)
262 } else {
263 let local_var_entity: Option<GetCustomTagsForWorkspaceError> = crate::from_str_patched(&local_var_content).ok();
264 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
265 Err(Error::ResponseError(local_var_error))
266 }
267}
268
269pub async fn get_queue_metrics(configuration: &configuration::Configuration, ) -> Result<Vec<models::GetQueueMetrics200ResponseInner>, Error<GetQueueMetricsError>> {
270 let local_var_configuration = configuration;
271
272 let local_var_client = &local_var_configuration.client;
273
274 let local_var_uri_str = format!("{}/workers/queue_metrics", local_var_configuration.base_path);
275 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
276
277 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
278 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
279 }
280 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
281 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
282 };
283
284 let local_var_req = local_var_req_builder.build()?;
285 let local_var_resp = local_var_client.execute(local_var_req).await?;
286
287 let local_var_status = local_var_resp.status();
288 let local_var_content = local_var_resp.text().await?;
289
290 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
291 crate::from_str_patched(&local_var_content).map_err(Error::from)
292 } else {
293 let local_var_entity: Option<GetQueueMetricsError> = crate::from_str_patched(&local_var_content).ok();
294 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
295 Err(Error::ResponseError(local_var_error))
296 }
297}
298
299pub async fn is_default_tags_per_workspace(configuration: &configuration::Configuration, ) -> Result<bool, Error<IsDefaultTagsPerWorkspaceError>> {
300 let local_var_configuration = configuration;
301
302 let local_var_client = &local_var_configuration.client;
303
304 let local_var_uri_str = format!("{}/workers/is_default_tags_per_workspace", local_var_configuration.base_path);
305 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
306
307 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
308 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
309 }
310 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
311 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
312 };
313
314 let local_var_req = local_var_req_builder.build()?;
315 let local_var_resp = local_var_client.execute(local_var_req).await?;
316
317 let local_var_status = local_var_resp.status();
318 let local_var_content = local_var_resp.text().await?;
319
320 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
321 crate::from_str_patched(&local_var_content).map_err(Error::from)
322 } else {
323 let local_var_entity: Option<IsDefaultTagsPerWorkspaceError> = crate::from_str_patched(&local_var_content).ok();
324 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
325 Err(Error::ResponseError(local_var_error))
326 }
327}
328
329pub async fn list_workers(configuration: &configuration::Configuration, page: Option<i32>, per_page: Option<i32>, ping_since: Option<i32>) -> Result<Vec<models::WorkerPing>, Error<ListWorkersError>> {
330 let local_var_configuration = configuration;
331
332 let local_var_client = &local_var_configuration.client;
333
334 let local_var_uri_str = format!("{}/workers/list", local_var_configuration.base_path);
335 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
336
337 if let Some(ref local_var_str) = page {
338 local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
339 }
340 if let Some(ref local_var_str) = per_page {
341 local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
342 }
343 if let Some(ref local_var_str) = ping_since {
344 local_var_req_builder = local_var_req_builder.query(&[("ping_since", &local_var_str.to_string())]);
345 }
346 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
347 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
348 }
349 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
350 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
351 };
352
353 let local_var_req = local_var_req_builder.build()?;
354 let local_var_resp = local_var_client.execute(local_var_req).await?;
355
356 let local_var_status = local_var_resp.status();
357 let local_var_content = local_var_resp.text().await?;
358
359 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
360 crate::from_str_patched(&local_var_content).map_err(Error::from)
361 } else {
362 let local_var_entity: Option<ListWorkersError> = crate::from_str_patched(&local_var_content).ok();
363 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
364 Err(Error::ResponseError(local_var_error))
365 }
366}
367