1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug)]
19pub struct ActionGetJobLogParams {
20 pub job_id: String,
22 pub x_request_id: Option<String>
24}
25
26#[derive(Clone, Debug)]
28pub struct ActionPendingJobsParams {
29 pub job_type: String,
31 pub action_request: models::ActionRequest,
32 pub x_request_id: Option<String>
34}
35
36#[derive(Clone, Debug)]
38pub struct GetWorkerPoolsParams {
39 pub x_request_id: Option<String>
41}
42
43#[derive(Clone, Debug)]
45pub struct GetWorkersParams {
46 pub pool_id: String,
48 pub x_request_id: Option<String>
50}
51
52#[derive(Clone, Debug)]
54pub struct ListJobQueuesParams {
55 pub x_request_id: Option<String>
57}
58
59#[derive(Clone, Debug)]
61pub struct StopRunningJobParams {
62 pub job_id: String,
64 pub x_request_id: Option<String>
66}
67
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum ActionGetJobLogError {
73 Status401(models::Errors),
74 Status403(models::Errors),
75 Status404(models::Errors),
76 Status500(models::Errors),
77 UnknownValue(serde_json::Value),
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum ActionPendingJobsError {
84 Status401(models::Errors),
85 Status403(models::Errors),
86 Status404(models::Errors),
87 Status422(models::Errors),
88 Status500(models::Errors),
89 UnknownValue(serde_json::Value),
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(untagged)]
95pub enum GetWorkerPoolsError {
96 Status401(models::Errors),
97 Status403(models::Errors),
98 Status500(models::Errors),
99 UnknownValue(serde_json::Value),
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(untagged)]
105pub enum GetWorkersError {
106 Status401(models::Errors),
107 Status403(models::Errors),
108 Status404(models::Errors),
109 Status500(models::Errors),
110 UnknownValue(serde_json::Value),
111}
112
113#[derive(Debug, Clone, Serialize, Deserialize)]
115#[serde(untagged)]
116pub enum ListJobQueuesError {
117 Status401(models::Errors),
118 Status403(models::Errors),
119 Status404(models::Errors),
120 Status500(models::Errors),
121 UnknownValue(serde_json::Value),
122}
123
124#[derive(Debug, Clone, Serialize, Deserialize)]
126#[serde(untagged)]
127pub enum StopRunningJobError {
128 Status401(models::Errors),
129 Status403(models::Errors),
130 Status404(models::Errors),
131 Status500(models::Errors),
132 UnknownValue(serde_json::Value),
133}
134
135
136pub async fn action_get_job_log(configuration: &configuration::Configuration, params: ActionGetJobLogParams) -> Result<String, Error<ActionGetJobLogError>> {
138
139 let uri_str = format!("{}/jobservice/jobs/{job_id}/log", configuration.base_path, job_id=crate::apis::urlencode(params.job_id));
140 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
141
142 if let Some(ref user_agent) = configuration.user_agent {
143 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
144 }
145 if let Some(param_value) = params.x_request_id {
146 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
147 }
148 if let Some(ref auth_conf) = configuration.basic_auth {
149 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
150 };
151
152 let req = req_builder.build()?;
153 let resp = configuration.client.execute(req).await?;
154
155 let status = resp.status();
156 let content_type = resp
157 .headers()
158 .get("content-type")
159 .and_then(|v| v.to_str().ok())
160 .unwrap_or("application/octet-stream");
161 let content_type = super::ContentType::from(content_type);
162
163 if !status.is_client_error() && !status.is_server_error() {
164 let content = resp.text().await?;
165 match content_type {
166 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
167 ContentType::Text => return Ok(content),
168 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
169 }
170 } else {
171 let content = resp.text().await?;
172 let entity: Option<ActionGetJobLogError> = serde_json::from_str(&content).ok();
173 Err(Error::ResponseError(ResponseContent { status, content, entity }))
174 }
175}
176
177pub async fn action_pending_jobs(configuration: &configuration::Configuration, params: ActionPendingJobsParams) -> Result<(), Error<ActionPendingJobsError>> {
179
180 let uri_str = format!("{}/jobservice/queues/{job_type}", configuration.base_path, job_type=crate::apis::urlencode(params.job_type));
181 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
182
183 if let Some(ref user_agent) = configuration.user_agent {
184 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
185 }
186 if let Some(param_value) = params.x_request_id {
187 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
188 }
189 if let Some(ref auth_conf) = configuration.basic_auth {
190 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
191 };
192 req_builder = req_builder.json(¶ms.action_request);
193
194 let req = req_builder.build()?;
195 let resp = configuration.client.execute(req).await?;
196
197 let status = resp.status();
198
199 if !status.is_client_error() && !status.is_server_error() {
200 Ok(())
201 } else {
202 let content = resp.text().await?;
203 let entity: Option<ActionPendingJobsError> = serde_json::from_str(&content).ok();
204 Err(Error::ResponseError(ResponseContent { status, content, entity }))
205 }
206}
207
208pub async fn get_worker_pools(configuration: &configuration::Configuration, params: GetWorkerPoolsParams) -> Result<Vec<models::WorkerPool>, Error<GetWorkerPoolsError>> {
210
211 let uri_str = format!("{}/jobservice/pools", configuration.base_path);
212 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
213
214 if let Some(ref user_agent) = configuration.user_agent {
215 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
216 }
217 if let Some(param_value) = params.x_request_id {
218 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
219 }
220 if let Some(ref auth_conf) = configuration.basic_auth {
221 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
222 };
223
224 let req = req_builder.build()?;
225 let resp = configuration.client.execute(req).await?;
226
227 let status = resp.status();
228 let content_type = resp
229 .headers()
230 .get("content-type")
231 .and_then(|v| v.to_str().ok())
232 .unwrap_or("application/octet-stream");
233 let content_type = super::ContentType::from(content_type);
234
235 if !status.is_client_error() && !status.is_server_error() {
236 let content = resp.text().await?;
237 match content_type {
238 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
239 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::WorkerPool>`"))),
240 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::WorkerPool>`")))),
241 }
242 } else {
243 let content = resp.text().await?;
244 let entity: Option<GetWorkerPoolsError> = serde_json::from_str(&content).ok();
245 Err(Error::ResponseError(ResponseContent { status, content, entity }))
246 }
247}
248
249pub async fn get_workers(configuration: &configuration::Configuration, params: GetWorkersParams) -> Result<Vec<models::Worker>, Error<GetWorkersError>> {
251
252 let uri_str = format!("{}/jobservice/pools/{pool_id}/workers", configuration.base_path, pool_id=crate::apis::urlencode(params.pool_id));
253 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
254
255 if let Some(ref user_agent) = configuration.user_agent {
256 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
257 }
258 if let Some(param_value) = params.x_request_id {
259 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
260 }
261 if let Some(ref auth_conf) = configuration.basic_auth {
262 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
263 };
264
265 let req = req_builder.build()?;
266 let resp = configuration.client.execute(req).await?;
267
268 let status = resp.status();
269 let content_type = resp
270 .headers()
271 .get("content-type")
272 .and_then(|v| v.to_str().ok())
273 .unwrap_or("application/octet-stream");
274 let content_type = super::ContentType::from(content_type);
275
276 if !status.is_client_error() && !status.is_server_error() {
277 let content = resp.text().await?;
278 match content_type {
279 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
280 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::Worker>`"))),
281 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::Worker>`")))),
282 }
283 } else {
284 let content = resp.text().await?;
285 let entity: Option<GetWorkersError> = serde_json::from_str(&content).ok();
286 Err(Error::ResponseError(ResponseContent { status, content, entity }))
287 }
288}
289
290pub async fn list_job_queues(configuration: &configuration::Configuration, params: ListJobQueuesParams) -> Result<Vec<models::JobQueue>, Error<ListJobQueuesError>> {
292
293 let uri_str = format!("{}/jobservice/queues", configuration.base_path);
294 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
295
296 if let Some(ref user_agent) = configuration.user_agent {
297 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
298 }
299 if let Some(param_value) = params.x_request_id {
300 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
301 }
302 if let Some(ref auth_conf) = configuration.basic_auth {
303 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
304 };
305
306 let req = req_builder.build()?;
307 let resp = configuration.client.execute(req).await?;
308
309 let status = resp.status();
310 let content_type = resp
311 .headers()
312 .get("content-type")
313 .and_then(|v| v.to_str().ok())
314 .unwrap_or("application/octet-stream");
315 let content_type = super::ContentType::from(content_type);
316
317 if !status.is_client_error() && !status.is_server_error() {
318 let content = resp.text().await?;
319 match content_type {
320 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
321 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::JobQueue>`"))),
322 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::JobQueue>`")))),
323 }
324 } else {
325 let content = resp.text().await?;
326 let entity: Option<ListJobQueuesError> = serde_json::from_str(&content).ok();
327 Err(Error::ResponseError(ResponseContent { status, content, entity }))
328 }
329}
330
331pub async fn stop_running_job(configuration: &configuration::Configuration, params: StopRunningJobParams) -> Result<(), Error<StopRunningJobError>> {
333
334 let uri_str = format!("{}/jobservice/jobs/{job_id}", configuration.base_path, job_id=crate::apis::urlencode(params.job_id));
335 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
336
337 if let Some(ref user_agent) = configuration.user_agent {
338 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
339 }
340 if let Some(param_value) = params.x_request_id {
341 req_builder = req_builder.header("X-Request-Id", param_value.to_string());
342 }
343 if let Some(ref auth_conf) = configuration.basic_auth {
344 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
345 };
346
347 let req = req_builder.build()?;
348 let resp = configuration.client.execute(req).await?;
349
350 let status = resp.status();
351
352 if !status.is_client_error() && !status.is_server_error() {
353 Ok(())
354 } else {
355 let content = resp.text().await?;
356 let entity: Option<StopRunningJobError> = serde_json::from_str(&content).ok();
357 Err(Error::ResponseError(ResponseContent { status, content, entity }))
358 }
359}
360