fireblocks_sdk/apis/
job_management_api.rs

1// Fireblocks API
2//
3// Fireblocks provides a suite of applications to manage digital asset operations and a complete development platform to build your business on the blockchain.  - Visit our website for more information: [Fireblocks Website](https://fireblocks.com) - Visit our developer docs: [Fireblocks DevPortal](https://developers.fireblocks.com)
4//
5// The version of the OpenAPI document: 1.8.0
6// Contact: developers@fireblocks.com
7// Generated by: https://openapi-generator.tech
8
9use {
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    /// POST /batch/{jobId}/cancel
24    ///
25    /// Stop the given job immediately. If the job is in the ‘Active’ state, the
26    /// job will be canceled after completing the current task. Vault accounts
27    /// and Wallets that are already created will not be affected.
28    async fn cancel_job(&self, params: CancelJobParams) -> Result<(), Error<CancelJobError>>;
29
30    /// POST /batch/{jobId}/continue
31    ///
32    /// Continue the given paused job.
33    async fn continue_job(&self, params: ContinueJobParams) -> Result<(), Error<ContinueJobError>>;
34
35    /// GET /batch/{jobId}
36    ///
37    /// Get an object describing the given job
38    async fn get_job(&self, params: GetJobParams) -> Result<models::Job, Error<GetJobError>>;
39
40    /// GET /batch/{jobId}/tasks
41    ///
42    /// Return a list of tasks for given job
43    async fn get_job_tasks(
44        &self,
45        params: GetJobTasksParams,
46    ) -> Result<Vec<models::Task>, Error<GetJobTasksError>>;
47
48    /// GET /batch/jobs
49    ///
50    /// Get an array of objects including all active, paused, canceled, and
51    /// complete jobs in a workspace.
52    async fn get_jobs(
53        &self,
54        params: GetJobsParams,
55    ) -> Result<Vec<models::Job>, Error<GetJobsError>>;
56
57    /// POST /batch/{jobId}/pause
58    ///
59    /// Pause the given job, after the current task is done. A paused job can
60    /// later be resumed by calling ‘continue’, or canceled.
61    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/// struct for passing parameters to the method [`JobManagementApi::cancel_job`]
75#[derive(Clone, Debug)]
76#[cfg_attr(feature = "bon", derive(::bon::Builder))]
77pub struct CancelJobParams {
78    /// The requested job id
79    pub job_id: String,
80    /// A unique identifier for the request. If the request is sent multiple
81    /// times with the same idempotency key, the server will return the same
82    /// response as the first request. The idempotency key is valid for 24
83    /// hours.
84    pub idempotency_key: Option<String>,
85}
86
87/// struct for passing parameters to the method
88/// [`JobManagementApi::continue_job`]
89#[derive(Clone, Debug)]
90#[cfg_attr(feature = "bon", derive(::bon::Builder))]
91pub struct ContinueJobParams {
92    /// The requested job id
93    pub job_id: String,
94    /// A unique identifier for the request. If the request is sent multiple
95    /// times with the same idempotency key, the server will return the same
96    /// response as the first request. The idempotency key is valid for 24
97    /// hours.
98    pub idempotency_key: Option<String>,
99}
100
101/// struct for passing parameters to the method [`JobManagementApi::get_job`]
102#[derive(Clone, Debug)]
103#[cfg_attr(feature = "bon", derive(::bon::Builder))]
104pub struct GetJobParams {
105    /// The requested job id
106    pub job_id: String,
107}
108
109/// struct for passing parameters to the method
110/// [`JobManagementApi::get_job_tasks`]
111#[derive(Clone, Debug)]
112#[cfg_attr(feature = "bon", derive(::bon::Builder))]
113pub struct GetJobTasksParams {
114    /// The requested job id
115    pub job_id: String,
116}
117
118/// struct for passing parameters to the method [`JobManagementApi::get_jobs`]
119#[derive(Clone, Debug)]
120#[cfg_attr(feature = "bon", derive(::bon::Builder))]
121pub struct GetJobsParams {
122    /// Start of time range in ms since 1970
123    pub from_time: Option<i32>,
124    /// End of time range in ms since 1970
125    pub to_time: Option<i32>,
126}
127
128/// struct for passing parameters to the method [`JobManagementApi::pause_job`]
129#[derive(Clone, Debug)]
130#[cfg_attr(feature = "bon", derive(::bon::Builder))]
131pub struct PauseJobParams {
132    /// The requested job id
133    pub job_id: String,
134    /// A unique identifier for the request. If the request is sent multiple
135    /// times with the same idempotency key, the server will return the same
136    /// response as the first request. The idempotency key is valid for 24
137    /// hours.
138    pub idempotency_key: Option<String>,
139}
140
141#[async_trait]
142impl JobManagementApi for JobManagementApiClient {
143    /// Stop the given job immediately. If the job is in the ‘Active’ state, the
144    /// job will be canceled after completing the current task. Vault accounts
145    /// and Wallets that are already created will not be affected.
146    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    /// Continue the given paused job.
194    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    /// Get an object describing the given job
242    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    /// Return a list of tasks for given job
305    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&lt;models::Task&gt;`",
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&lt;models::Task&gt;`"
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    /// Get an array of objects including all active, paused, canceled, and
371    /// complete jobs in a workspace.
372    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", &param_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", &param_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&lt;models::Job&gt;`",
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&lt;models::Job&gt;`"
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    /// Pause the given job, after the current task is done. A paused job can
442    /// later be resumed by calling ‘continue’, or canceled.
443    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/// struct for typed errors of method [`JobManagementApi::cancel_job`]
492#[derive(Debug, Clone, Serialize, Deserialize)]
493#[serde(untagged)]
494pub enum CancelJobError {
495    DefaultResponse(models::ErrorSchema),
496    UnknownValue(serde_json::Value),
497}
498
499/// struct for typed errors of method [`JobManagementApi::continue_job`]
500#[derive(Debug, Clone, Serialize, Deserialize)]
501#[serde(untagged)]
502pub enum ContinueJobError {
503    DefaultResponse(models::ErrorSchema),
504    UnknownValue(serde_json::Value),
505}
506
507/// struct for typed errors of method [`JobManagementApi::get_job`]
508#[derive(Debug, Clone, Serialize, Deserialize)]
509#[serde(untagged)]
510pub enum GetJobError {
511    DefaultResponse(models::ErrorSchema),
512    UnknownValue(serde_json::Value),
513}
514
515/// struct for typed errors of method [`JobManagementApi::get_job_tasks`]
516#[derive(Debug, Clone, Serialize, Deserialize)]
517#[serde(untagged)]
518pub enum GetJobTasksError {
519    DefaultResponse(models::ErrorSchema),
520    UnknownValue(serde_json::Value),
521}
522
523/// struct for typed errors of method [`JobManagementApi::get_jobs`]
524#[derive(Debug, Clone, Serialize, Deserialize)]
525#[serde(untagged)]
526pub enum GetJobsError {
527    DefaultResponse(models::ErrorSchema),
528    UnknownValue(serde_json::Value),
529}
530
531/// struct for typed errors of method [`JobManagementApi::pause_job`]
532#[derive(Debug, Clone, Serialize, Deserialize)]
533#[serde(untagged)]
534pub enum PauseJobError {
535    DefaultResponse(models::ErrorSchema),
536    UnknownValue(serde_json::Value),
537}