zeebe_rs/job/
update_retries.rs

1use crate::{Client, ClientError, proto};
2
3pub struct Initial;
4pub struct WithKey;
5pub struct WithRetries;
6
7pub trait UpdateJobRetriesRequestState {}
8impl UpdateJobRetriesRequestState for Initial {}
9impl UpdateJobRetriesRequestState for WithKey {}
10impl UpdateJobRetriesRequestState for WithRetries {}
11
12/// Request to update the number of retries for a job
13///
14/// This struct represents a request to update the number of retries for a
15/// job in Zeebe.
16/// It uses a builder pattern with different states to ensure that the job key
17/// and retries are set before sending the request.
18///
19/// # Examples
20/// ```ignore
21/// client
22///     .update_job_retries()
23///     .with_job_key(123456)
24///     .with_retries(1)
25///     .send()
26///     .await?;
27/// ```
28#[derive(Debug, Clone)]
29pub struct UpdateJobRetriesRequest<T: UpdateJobRetriesRequestState> {
30    client: Client,
31    job_key: i64,
32    retries: i32,
33    operation_reference: Option<u64>,
34    _state: std::marker::PhantomData<T>,
35}
36
37impl<T: UpdateJobRetriesRequestState> UpdateJobRetriesRequest<T> {
38    pub(crate) fn new(client: Client) -> UpdateJobRetriesRequest<Initial> {
39        UpdateJobRetriesRequest {
40            client,
41            job_key: 0,
42            retries: 0,
43            operation_reference: None,
44            _state: std::marker::PhantomData,
45        }
46    }
47
48    fn transition<NewState: UpdateJobRetriesRequestState>(
49        self,
50    ) -> UpdateJobRetriesRequest<NewState> {
51        UpdateJobRetriesRequest {
52            client: self.client,
53            job_key: self.job_key,
54            retries: self.retries,
55            operation_reference: self.operation_reference,
56            _state: std::marker::PhantomData,
57        }
58    }
59}
60
61impl UpdateJobRetriesRequest<Initial> {
62    /// Sets the job key to identify which job to update
63    ///
64    /// # Arguments
65    ///
66    /// * `job_key` - The unique key identifying the job
67    ///
68    /// # Returns
69    ///
70    /// The UpdateJobRetriesRequest in the WithKey state
71    pub fn with_job_key(mut self, job_key: i64) -> UpdateJobRetriesRequest<WithKey> {
72        self.job_key = job_key;
73        self.transition()
74    }
75}
76
77impl UpdateJobRetriesRequest<WithKey> {
78    /// Sets the new number of retries for the job
79    ///
80    /// # Arguments
81    ///
82    /// * `retries` - The new number of retries for the job
83    ///
84    /// # Returns
85    ///
86    /// The UpdateJobRetriesRequest in the WithRetries state
87    pub fn with_retries(mut self, retries: i32) -> UpdateJobRetriesRequest<WithRetries> {
88        self.retries = retries;
89        self.transition()
90    }
91}
92
93impl UpdateJobRetriesRequest<WithRetries> {
94    /// Sends the job retries update request to Zeebe.
95    ///
96    /// # Returns
97    ///
98    /// A Result containing the UpdateJobRetriesResponse if successful, or a ClientError if there was an error
99    pub async fn send(mut self) -> Result<UpdateJobRetriesResponse, ClientError> {
100        let res = self
101            .client
102            .gateway_client
103            .update_job_retries(proto::UpdateJobRetriesRequest {
104                job_key: self.job_key,
105                retries: self.retries,
106                operation_reference: self.operation_reference,
107            })
108            .await?;
109
110        Ok(res.into_inner().into())
111    }
112
113    /// Sets a reference key for tracking this operation
114    ///
115    /// # Arguments
116    ///
117    /// * `operation_reference` - The reference key to track the operation
118    ///
119    /// # Returns
120    ///
121    /// The updated UpdateJobRetriesRequest with the operation reference set
122    pub fn with_operation_reference(mut self, operation_reference: u64) -> Self {
123        self.operation_reference = Some(operation_reference);
124        self
125    }
126}
127
128/// Response from updating job retries
129#[derive(Debug, Clone)]
130pub struct UpdateJobRetriesResponse {}
131
132impl From<proto::UpdateJobRetriesResponse> for UpdateJobRetriesResponse {
133    fn from(_value: proto::UpdateJobRetriesResponse) -> UpdateJobRetriesResponse {
134        UpdateJobRetriesResponse {}
135    }
136}