1use {
10 super::{Error, configuration},
11 crate::{
12 apis::{ContentType, ResponseContent},
13 models,
14 },
15 async_trait::async_trait,
16 reqwest,
17 serde::{Deserialize, Serialize, de::Error as _},
18 std::sync::Arc,
19};
20
21#[async_trait]
22pub trait JobManagementApi: Send + Sync {
23 async fn cancel_job(&self, params: CancelJobParams) -> Result<(), Error<CancelJobError>>;
29
30 async fn continue_job(&self, params: ContinueJobParams) -> Result<(), Error<ContinueJobError>>;
34
35 async fn get_job(&self, params: GetJobParams) -> Result<models::Job, Error<GetJobError>>;
39
40 async fn get_job_tasks(
44 &self,
45 params: GetJobTasksParams,
46 ) -> Result<Vec<models::Task>, Error<GetJobTasksError>>;
47
48 async fn get_jobs(
53 &self,
54 params: GetJobsParams,
55 ) -> Result<Vec<models::Job>, Error<GetJobsError>>;
56
57 async fn pause_job(&self, params: PauseJobParams) -> Result<(), Error<PauseJobError>>;
62}
63
64pub struct JobManagementApiClient {
65 configuration: Arc<configuration::Configuration>,
66}
67
68impl JobManagementApiClient {
69 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
70 Self { configuration }
71 }
72}
73
74#[derive(Clone, Debug)]
76#[cfg_attr(feature = "bon", derive(::bon::Builder))]
77pub struct CancelJobParams {
78 pub job_id: String,
80 pub idempotency_key: Option<String>,
85}
86
87#[derive(Clone, Debug)]
90#[cfg_attr(feature = "bon", derive(::bon::Builder))]
91pub struct ContinueJobParams {
92 pub job_id: String,
94 pub idempotency_key: Option<String>,
99}
100
101#[derive(Clone, Debug)]
103#[cfg_attr(feature = "bon", derive(::bon::Builder))]
104pub struct GetJobParams {
105 pub job_id: String,
107}
108
109#[derive(Clone, Debug)]
112#[cfg_attr(feature = "bon", derive(::bon::Builder))]
113pub struct GetJobTasksParams {
114 pub job_id: String,
116}
117
118#[derive(Clone, Debug)]
120#[cfg_attr(feature = "bon", derive(::bon::Builder))]
121pub struct GetJobsParams {
122 pub from_time: Option<i32>,
124 pub to_time: Option<i32>,
126}
127
128#[derive(Clone, Debug)]
130#[cfg_attr(feature = "bon", derive(::bon::Builder))]
131pub struct PauseJobParams {
132 pub job_id: String,
134 pub idempotency_key: Option<String>,
139}
140
141#[async_trait]
142impl JobManagementApi for JobManagementApiClient {
143 async fn cancel_job(&self, params: CancelJobParams) -> Result<(), Error<CancelJobError>> {
147 let CancelJobParams {
148 job_id,
149 idempotency_key,
150 } = params;
151
152 let local_var_configuration = &self.configuration;
153
154 let local_var_client = &local_var_configuration.client;
155
156 let local_var_uri_str = format!(
157 "{}/batch/{jobId}/cancel",
158 local_var_configuration.base_path,
159 jobId = crate::apis::urlencode(job_id)
160 );
161 let mut local_var_req_builder =
162 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
163
164 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
165 local_var_req_builder = local_var_req_builder
166 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
167 }
168 if let Some(local_var_param_value) = idempotency_key {
169 local_var_req_builder =
170 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
171 }
172
173 let local_var_req = local_var_req_builder.build()?;
174 let local_var_resp = local_var_client.execute(local_var_req).await?;
175
176 let local_var_status = local_var_resp.status();
177 let local_var_content = local_var_resp.text().await?;
178
179 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
180 Ok(())
181 } else {
182 let local_var_entity: Option<CancelJobError> =
183 serde_json::from_str(&local_var_content).ok();
184 let local_var_error = ResponseContent {
185 status: local_var_status,
186 content: local_var_content,
187 entity: local_var_entity,
188 };
189 Err(Error::ResponseError(local_var_error))
190 }
191 }
192
193 async fn continue_job(&self, params: ContinueJobParams) -> Result<(), Error<ContinueJobError>> {
195 let ContinueJobParams {
196 job_id,
197 idempotency_key,
198 } = params;
199
200 let local_var_configuration = &self.configuration;
201
202 let local_var_client = &local_var_configuration.client;
203
204 let local_var_uri_str = format!(
205 "{}/batch/{jobId}/continue",
206 local_var_configuration.base_path,
207 jobId = crate::apis::urlencode(job_id)
208 );
209 let mut local_var_req_builder =
210 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
211
212 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
213 local_var_req_builder = local_var_req_builder
214 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
215 }
216 if let Some(local_var_param_value) = idempotency_key {
217 local_var_req_builder =
218 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
219 }
220
221 let local_var_req = local_var_req_builder.build()?;
222 let local_var_resp = local_var_client.execute(local_var_req).await?;
223
224 let local_var_status = local_var_resp.status();
225 let local_var_content = local_var_resp.text().await?;
226
227 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
228 Ok(())
229 } else {
230 let local_var_entity: Option<ContinueJobError> =
231 serde_json::from_str(&local_var_content).ok();
232 let local_var_error = ResponseContent {
233 status: local_var_status,
234 content: local_var_content,
235 entity: local_var_entity,
236 };
237 Err(Error::ResponseError(local_var_error))
238 }
239 }
240
241 async fn get_job(&self, params: GetJobParams) -> Result<models::Job, Error<GetJobError>> {
243 let GetJobParams { job_id } = params;
244
245 let local_var_configuration = &self.configuration;
246
247 let local_var_client = &local_var_configuration.client;
248
249 let local_var_uri_str = format!(
250 "{}/batch/{jobId}",
251 local_var_configuration.base_path,
252 jobId = crate::apis::urlencode(job_id)
253 );
254 let mut local_var_req_builder =
255 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
256
257 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
258 local_var_req_builder = local_var_req_builder
259 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
260 }
261
262 let local_var_req = local_var_req_builder.build()?;
263 let local_var_resp = local_var_client.execute(local_var_req).await?;
264
265 let local_var_status = local_var_resp.status();
266 let local_var_content_type = local_var_resp
267 .headers()
268 .get("content-type")
269 .and_then(|v| v.to_str().ok())
270 .unwrap_or("application/octet-stream");
271 let local_var_content_type = super::ContentType::from(local_var_content_type);
272 let local_var_content = local_var_resp.text().await?;
273
274 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
275 match local_var_content_type {
276 ContentType::Json => {
277 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
278 }
279 ContentType::Text => {
280 return Err(Error::from(serde_json::Error::custom(
281 "Received `text/plain` content type response that cannot be converted to \
282 `models::Job`",
283 )));
284 }
285 ContentType::Unsupported(local_var_unknown_type) => {
286 return Err(Error::from(serde_json::Error::custom(format!(
287 "Received `{local_var_unknown_type}` content type response that cannot be \
288 converted to `models::Job`"
289 ))));
290 }
291 }
292 } else {
293 let local_var_entity: Option<GetJobError> =
294 serde_json::from_str(&local_var_content).ok();
295 let local_var_error = ResponseContent {
296 status: local_var_status,
297 content: local_var_content,
298 entity: local_var_entity,
299 };
300 Err(Error::ResponseError(local_var_error))
301 }
302 }
303
304 async fn get_job_tasks(
306 &self,
307 params: GetJobTasksParams,
308 ) -> Result<Vec<models::Task>, Error<GetJobTasksError>> {
309 let GetJobTasksParams { job_id } = params;
310
311 let local_var_configuration = &self.configuration;
312
313 let local_var_client = &local_var_configuration.client;
314
315 let local_var_uri_str = format!(
316 "{}/batch/{jobId}/tasks",
317 local_var_configuration.base_path,
318 jobId = crate::apis::urlencode(job_id)
319 );
320 let mut local_var_req_builder =
321 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
322
323 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
324 local_var_req_builder = local_var_req_builder
325 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
326 }
327
328 let local_var_req = local_var_req_builder.build()?;
329 let local_var_resp = local_var_client.execute(local_var_req).await?;
330
331 let local_var_status = local_var_resp.status();
332 let local_var_content_type = local_var_resp
333 .headers()
334 .get("content-type")
335 .and_then(|v| v.to_str().ok())
336 .unwrap_or("application/octet-stream");
337 let local_var_content_type = super::ContentType::from(local_var_content_type);
338 let local_var_content = local_var_resp.text().await?;
339
340 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
341 match local_var_content_type {
342 ContentType::Json => {
343 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
344 }
345 ContentType::Text => {
346 return Err(Error::from(serde_json::Error::custom(
347 "Received `text/plain` content type response that cannot be converted to \
348 `Vec<models::Task>`",
349 )));
350 }
351 ContentType::Unsupported(local_var_unknown_type) => {
352 return Err(Error::from(serde_json::Error::custom(format!(
353 "Received `{local_var_unknown_type}` content type response that cannot be \
354 converted to `Vec<models::Task>`"
355 ))));
356 }
357 }
358 } else {
359 let local_var_entity: Option<GetJobTasksError> =
360 serde_json::from_str(&local_var_content).ok();
361 let local_var_error = ResponseContent {
362 status: local_var_status,
363 content: local_var_content,
364 entity: local_var_entity,
365 };
366 Err(Error::ResponseError(local_var_error))
367 }
368 }
369
370 async fn get_jobs(
373 &self,
374 params: GetJobsParams,
375 ) -> Result<Vec<models::Job>, Error<GetJobsError>> {
376 let GetJobsParams { from_time, to_time } = params;
377
378 let local_var_configuration = &self.configuration;
379
380 let local_var_client = &local_var_configuration.client;
381
382 let local_var_uri_str = format!("{}/batch/jobs", local_var_configuration.base_path);
383 let mut local_var_req_builder =
384 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
385
386 if let Some(ref param_value) = from_time {
387 local_var_req_builder =
388 local_var_req_builder.query(&[("fromTime", ¶m_value.to_string())]);
389 }
390 if let Some(ref param_value) = to_time {
391 local_var_req_builder =
392 local_var_req_builder.query(&[("toTime", ¶m_value.to_string())]);
393 }
394 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
395 local_var_req_builder = local_var_req_builder
396 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
397 }
398
399 let local_var_req = local_var_req_builder.build()?;
400 let local_var_resp = local_var_client.execute(local_var_req).await?;
401
402 let local_var_status = local_var_resp.status();
403 let local_var_content_type = local_var_resp
404 .headers()
405 .get("content-type")
406 .and_then(|v| v.to_str().ok())
407 .unwrap_or("application/octet-stream");
408 let local_var_content_type = super::ContentType::from(local_var_content_type);
409 let local_var_content = local_var_resp.text().await?;
410
411 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
412 match local_var_content_type {
413 ContentType::Json => {
414 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
415 }
416 ContentType::Text => {
417 return Err(Error::from(serde_json::Error::custom(
418 "Received `text/plain` content type response that cannot be converted to \
419 `Vec<models::Job>`",
420 )));
421 }
422 ContentType::Unsupported(local_var_unknown_type) => {
423 return Err(Error::from(serde_json::Error::custom(format!(
424 "Received `{local_var_unknown_type}` content type response that cannot be \
425 converted to `Vec<models::Job>`"
426 ))));
427 }
428 }
429 } else {
430 let local_var_entity: Option<GetJobsError> =
431 serde_json::from_str(&local_var_content).ok();
432 let local_var_error = ResponseContent {
433 status: local_var_status,
434 content: local_var_content,
435 entity: local_var_entity,
436 };
437 Err(Error::ResponseError(local_var_error))
438 }
439 }
440
441 async fn pause_job(&self, params: PauseJobParams) -> Result<(), Error<PauseJobError>> {
444 let PauseJobParams {
445 job_id,
446 idempotency_key,
447 } = params;
448
449 let local_var_configuration = &self.configuration;
450
451 let local_var_client = &local_var_configuration.client;
452
453 let local_var_uri_str = format!(
454 "{}/batch/{jobId}/pause",
455 local_var_configuration.base_path,
456 jobId = crate::apis::urlencode(job_id)
457 );
458 let mut local_var_req_builder =
459 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
460
461 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
462 local_var_req_builder = local_var_req_builder
463 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
464 }
465 if let Some(local_var_param_value) = idempotency_key {
466 local_var_req_builder =
467 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
468 }
469
470 let local_var_req = local_var_req_builder.build()?;
471 let local_var_resp = local_var_client.execute(local_var_req).await?;
472
473 let local_var_status = local_var_resp.status();
474 let local_var_content = local_var_resp.text().await?;
475
476 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
477 Ok(())
478 } else {
479 let local_var_entity: Option<PauseJobError> =
480 serde_json::from_str(&local_var_content).ok();
481 let local_var_error = ResponseContent {
482 status: local_var_status,
483 content: local_var_content,
484 entity: local_var_entity,
485 };
486 Err(Error::ResponseError(local_var_error))
487 }
488 }
489}
490
491#[derive(Debug, Clone, Serialize, Deserialize)]
493#[serde(untagged)]
494pub enum CancelJobError {
495 DefaultResponse(models::ErrorSchema),
496 UnknownValue(serde_json::Value),
497}
498
499#[derive(Debug, Clone, Serialize, Deserialize)]
501#[serde(untagged)]
502pub enum ContinueJobError {
503 DefaultResponse(models::ErrorSchema),
504 UnknownValue(serde_json::Value),
505}
506
507#[derive(Debug, Clone, Serialize, Deserialize)]
509#[serde(untagged)]
510pub enum GetJobError {
511 DefaultResponse(models::ErrorSchema),
512 UnknownValue(serde_json::Value),
513}
514
515#[derive(Debug, Clone, Serialize, Deserialize)]
517#[serde(untagged)]
518pub enum GetJobTasksError {
519 DefaultResponse(models::ErrorSchema),
520 UnknownValue(serde_json::Value),
521}
522
523#[derive(Debug, Clone, Serialize, Deserialize)]
525#[serde(untagged)]
526pub enum GetJobsError {
527 DefaultResponse(models::ErrorSchema),
528 UnknownValue(serde_json::Value),
529}
530
531#[derive(Debug, Clone, Serialize, Deserialize)]
533#[serde(untagged)]
534pub enum PauseJobError {
535 DefaultResponse(models::ErrorSchema),
536 UnknownValue(serde_json::Value),
537}