zeebe_rs/
incident.rs

1use crate::{Client, ClientError, proto};
2
3pub struct Initial;
4pub struct WithKey;
5
6pub trait ResolveIncidentRequestState {}
7impl ResolveIncidentRequestState for Initial {}
8impl ResolveIncidentRequestState for WithKey {}
9
10/// Request builder for resolving incidents in Zeebe.
11///
12/// This simply marks the incident as resolved. Most likely a call to
13/// UpdateJobRetries or SetVariables will be necessary to actually resolve the
14/// underlying problem before calling this.
15///
16/// # Examples
17/// ```ignore
18/// client
19///     .resolve_incident()
20///     .with_incident_key(123456)
21///     .send()
22///     .await?;
23/// ```
24#[derive(Debug, Clone)]
25pub struct ResolveIncidentRequest<T: ResolveIncidentRequestState> {
26    client: Client,
27    incident_key: i64,
28    operation_reference: Option<u64>,
29    _state: std::marker::PhantomData<T>,
30}
31
32impl<T: ResolveIncidentRequestState> ResolveIncidentRequest<T> {
33    pub(crate) fn new(client: Client) -> ResolveIncidentRequest<Initial> {
34        ResolveIncidentRequest {
35            client,
36            incident_key: 0,
37            operation_reference: None,
38            _state: std::marker::PhantomData,
39        }
40    }
41
42    fn transition<NewState: ResolveIncidentRequestState>(self) -> ResolveIncidentRequest<NewState> {
43        ResolveIncidentRequest {
44            client: self.client,
45            incident_key: self.incident_key,
46            operation_reference: self.operation_reference,
47            _state: std::marker::PhantomData,
48        }
49    }
50}
51
52impl ResolveIncidentRequest<Initial> {
53    /// Sets the unique identifier of the incident to resolve
54    ///
55    /// This is a required field and must be set before sending the request.
56    ///
57    /// # Arguments
58    /// * `incident_key` - The unique key identifying the incident to be resolved
59    ///
60    /// # Returns
61    /// The updated `ResolveIncidentRequest` with the incident key set
62    pub fn with_incident_key(mut self, incident_key: i64) -> ResolveIncidentRequest<WithKey> {
63        self.incident_key = incident_key;
64        self.transition()
65    }
66}
67
68impl ResolveIncidentRequest<WithKey> {
69    /// Sends the incident resolution request to the broker
70    ///
71    /// # Returns
72    /// * `Ok(ResolveIncidentResponse)` - The incident was successfully marked as resolved
73    /// * `Err(ClientError)` - If the request fails
74    ///
75    /// # Errors
76    /// Will return error if:
77    /// * No incident exists with the given key
78    /// * The connection to the broker fails
79    pub async fn send(mut self) -> Result<ResolveIncidentResponse, ClientError> {
80        let res = self
81            .client
82            .gateway_client
83            .resolve_incident(proto::ResolveIncidentRequest {
84                incident_key: self.incident_key,
85                operation_reference: self.operation_reference,
86            })
87            .await?;
88
89        Ok(res.into_inner().into())
90    }
91
92    /// Sets a reference key that will be included in all records resulting from this operation
93    ///
94    /// This is an optional identifier that can be used to track the operation across the system.
95    ///
96    /// # Arguments
97    /// * `operation_reference` - The reference key to set
98    ///
99    /// # Returns
100    /// The updated `ResolveIncidentRequest` with the operation reference set
101    pub fn with_operation_reference(mut self, operation_reference: u64) -> Self {
102        self.operation_reference = Some(operation_reference);
103        self
104    }
105}
106
107/// Empty response received after successfully resolving an incident
108#[derive(Debug, Clone)]
109pub struct ResolveIncidentResponse {}
110
111impl From<proto::ResolveIncidentResponse> for ResolveIncidentResponse {
112    fn from(_value: proto::ResolveIncidentResponse) -> ResolveIncidentResponse {
113        ResolveIncidentResponse {}
114    }
115}