windmill_api/apis/
worker_api.rs

1/*
2 * Windmill API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.537.0
7 * Contact: contact@windmill.dev
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`exists_workers_with_tags`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ExistsWorkersWithTagsError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`ge_default_tags`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GeDefaultTagsError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_counts_of_jobs_waiting_per_tag`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetCountsOfJobsWaitingPerTagError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_counts_of_running_jobs_per_tag`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetCountsOfRunningJobsPerTagError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_custom_tags`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetCustomTagsError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`get_queue_metrics`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetQueueMetricsError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`is_default_tags_per_workspace`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum IsDefaultTagsPerWorkspaceError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`list_workers`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum ListWorkersError {
71    UnknownValue(serde_json::Value),
72}
73
74
75pub async fn exists_workers_with_tags(configuration: &configuration::Configuration, tags: &str) -> Result<std::collections::HashMap<String, bool>, Error<ExistsWorkersWithTagsError>> {
76    let local_var_configuration = configuration;
77
78    let local_var_client = &local_var_configuration.client;
79
80    let local_var_uri_str = format!("{}/workers/exists_workers_with_tags", local_var_configuration.base_path);
81    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
82
83    local_var_req_builder = local_var_req_builder.query(&[("tags", &tags.to_string())]);
84    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
85        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
86    }
87    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
88        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
89    };
90
91    let local_var_req = local_var_req_builder.build()?;
92    let local_var_resp = local_var_client.execute(local_var_req).await?;
93
94    let local_var_status = local_var_resp.status();
95    let local_var_content = local_var_resp.text().await?;
96
97    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
98        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
99    } else {
100        let local_var_entity: Option<ExistsWorkersWithTagsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
101        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
102        Err(Error::ResponseError(local_var_error))
103    }
104}
105
106pub async fn ge_default_tags(configuration: &configuration::Configuration, ) -> Result<Vec<String>, Error<GeDefaultTagsError>> {
107    let local_var_configuration = configuration;
108
109    let local_var_client = &local_var_configuration.client;
110
111    let local_var_uri_str = format!("{}/workers/get_default_tags", local_var_configuration.base_path);
112    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
113
114    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
115        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
116    }
117    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
118        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
119    };
120
121    let local_var_req = local_var_req_builder.build()?;
122    let local_var_resp = local_var_client.execute(local_var_req).await?;
123
124    let local_var_status = local_var_resp.status();
125    let local_var_content = local_var_resp.text().await?;
126
127    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
128        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
129    } else {
130        let local_var_entity: Option<GeDefaultTagsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
131        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
132        Err(Error::ResponseError(local_var_error))
133    }
134}
135
136pub async fn get_counts_of_jobs_waiting_per_tag(configuration: &configuration::Configuration, ) -> Result<std::collections::HashMap<String, i32>, Error<GetCountsOfJobsWaitingPerTagError>> {
137    let local_var_configuration = configuration;
138
139    let local_var_client = &local_var_configuration.client;
140
141    let local_var_uri_str = format!("{}/workers/queue_counts", local_var_configuration.base_path);
142    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
143
144    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
145        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
146    }
147    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
148        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
149    };
150
151    let local_var_req = local_var_req_builder.build()?;
152    let local_var_resp = local_var_client.execute(local_var_req).await?;
153
154    let local_var_status = local_var_resp.status();
155    let local_var_content = local_var_resp.text().await?;
156
157    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
158        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
159    } else {
160        let local_var_entity: Option<GetCountsOfJobsWaitingPerTagError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
161        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
162        Err(Error::ResponseError(local_var_error))
163    }
164}
165
166pub async fn get_counts_of_running_jobs_per_tag(configuration: &configuration::Configuration, ) -> Result<std::collections::HashMap<String, i32>, Error<GetCountsOfRunningJobsPerTagError>> {
167    let local_var_configuration = configuration;
168
169    let local_var_client = &local_var_configuration.client;
170
171    let local_var_uri_str = format!("{}/workers/queue_running_counts", local_var_configuration.base_path);
172    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
173
174    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
175        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
176    }
177    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
178        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
179    };
180
181    let local_var_req = local_var_req_builder.build()?;
182    let local_var_resp = local_var_client.execute(local_var_req).await?;
183
184    let local_var_status = local_var_resp.status();
185    let local_var_content = local_var_resp.text().await?;
186
187    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
188        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
189    } else {
190        let local_var_entity: Option<GetCountsOfRunningJobsPerTagError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
191        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
192        Err(Error::ResponseError(local_var_error))
193    }
194}
195
196pub async fn get_custom_tags(configuration: &configuration::Configuration, workspace: Option<&str>, show_workspace_restriction: Option<bool>) -> Result<Vec<String>, Error<GetCustomTagsError>> {
197    let local_var_configuration = configuration;
198
199    let local_var_client = &local_var_configuration.client;
200
201    let local_var_uri_str = format!("{}/workers/custom_tags", local_var_configuration.base_path);
202    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
203
204    if let Some(ref local_var_str) = workspace {
205        local_var_req_builder = local_var_req_builder.query(&[("workspace", &local_var_str.to_string())]);
206    }
207    if let Some(ref local_var_str) = show_workspace_restriction {
208        local_var_req_builder = local_var_req_builder.query(&[("show_workspace_restriction", &local_var_str.to_string())]);
209    }
210    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
211        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
212    }
213    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
214        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
215    };
216
217    let local_var_req = local_var_req_builder.build()?;
218    let local_var_resp = local_var_client.execute(local_var_req).await?;
219
220    let local_var_status = local_var_resp.status();
221    let local_var_content = local_var_resp.text().await?;
222
223    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
224        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
225    } else {
226        let local_var_entity: Option<GetCustomTagsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
227        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
228        Err(Error::ResponseError(local_var_error))
229    }
230}
231
232pub async fn get_queue_metrics(configuration: &configuration::Configuration, ) -> Result<Vec<models::GetQueueMetrics200ResponseInner>, Error<GetQueueMetricsError>> {
233    let local_var_configuration = configuration;
234
235    let local_var_client = &local_var_configuration.client;
236
237    let local_var_uri_str = format!("{}/workers/queue_metrics", local_var_configuration.base_path);
238    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
239
240    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
241        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
242    }
243    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
244        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
245    };
246
247    let local_var_req = local_var_req_builder.build()?;
248    let local_var_resp = local_var_client.execute(local_var_req).await?;
249
250    let local_var_status = local_var_resp.status();
251    let local_var_content = local_var_resp.text().await?;
252
253    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
254        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
255    } else {
256        let local_var_entity: Option<GetQueueMetricsError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
257        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
258        Err(Error::ResponseError(local_var_error))
259    }
260}
261
262pub async fn is_default_tags_per_workspace(configuration: &configuration::Configuration, ) -> Result<bool, Error<IsDefaultTagsPerWorkspaceError>> {
263    let local_var_configuration = configuration;
264
265    let local_var_client = &local_var_configuration.client;
266
267    let local_var_uri_str = format!("{}/workers/is_default_tags_per_workspace", local_var_configuration.base_path);
268    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
269
270    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
271        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
272    }
273    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
274        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
275    };
276
277    let local_var_req = local_var_req_builder.build()?;
278    let local_var_resp = local_var_client.execute(local_var_req).await?;
279
280    let local_var_status = local_var_resp.status();
281    let local_var_content = local_var_resp.text().await?;
282
283    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
284        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
285    } else {
286        let local_var_entity: Option<IsDefaultTagsPerWorkspaceError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
287        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
288        Err(Error::ResponseError(local_var_error))
289    }
290}
291
292pub async fn list_workers(configuration: &configuration::Configuration, page: Option<i32>, per_page: Option<i32>, ping_since: Option<i32>) -> Result<Vec<models::WorkerPing>, Error<ListWorkersError>> {
293    let local_var_configuration = configuration;
294
295    let local_var_client = &local_var_configuration.client;
296
297    let local_var_uri_str = format!("{}/workers/list", local_var_configuration.base_path);
298    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
299
300    if let Some(ref local_var_str) = page {
301        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
302    }
303    if let Some(ref local_var_str) = per_page {
304        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
305    }
306    if let Some(ref local_var_str) = ping_since {
307        local_var_req_builder = local_var_req_builder.query(&[("ping_since", &local_var_str.to_string())]);
308    }
309    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
310        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
311    }
312    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
313        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
314    };
315
316    let local_var_req = local_var_req_builder.build()?;
317    let local_var_resp = local_var_client.execute(local_var_req).await?;
318
319    let local_var_status = local_var_resp.status();
320    let local_var_content = local_var_resp.text().await?;
321
322    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
323        crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).map_err(Error::from)
324    } else {
325        let local_var_entity: Option<ListWorkersError> = crate::from_str_patched/* Externally injected from /build.nu */(&local_var_content).ok();
326        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
327        Err(Error::ResponseError(local_var_error))
328    }
329}
330