Skip to main content

brevo_rust/api/resources/process/
process.rs

1use crate::api::*;
2use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
3use reqwest::Method;
4
5pub struct ProcessClient {
6    pub http_client: HttpClient,
7}
8
9impl ProcessClient {
10    pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
11        Ok(Self {
12            http_client: HttpClient::new(config.clone())?,
13        })
14    }
15
16    /// Retrieves a list of background processes from your Brevo account with filtering and pagination.
17    ///
18    /// **Use this to:**
19    /// - Monitor background process activity and status
20    /// - Track long-running operations and tasks
21    /// - Find process IDs for detailed status checking
22    /// - Review process history and performance
23    /// - Identify failed or stuck processes for troubleshooting
24    ///
25    /// **Key information returned:**
26    /// - Process details (ID, name, status)
27    /// - Export download URLs for completed export processes
28    /// - Import details with CSV report URLs for completed import processes
29    /// - Total count of processes for pagination
30    ///
31    /// **Important considerations:**
32    /// - Background processes handle long-running operations like imports and exports
33    /// - Process status indicates current state (queued, processing, completed)
34    /// - Export processes provide download URLs when completed
35    /// - Import processes provide CSV report URLs with details about problematic records
36    /// - Use pagination for accounts with many historical processes
37    /// - Sort options available for creation order (ascending or descending)
38    /// - Default limit is 10 results per page, maximum is 50
39    ///
40    /// # Arguments
41    ///
42    /// * `limit` - Number limitation for the result returned
43    /// * `offset` - Beginning point in the list to retrieve from.
44    /// * `sort` - Sort the results in the ascending/descending order of record creation.
45    /// Default order is **descending** if `sort` is not passed
46    /// * `options` - Additional request options such as headers, timeout, etc.
47    ///
48    /// # Returns
49    ///
50    /// JSON response from the API
51    ///
52    /// # Examples
53    ///
54    /// ```no_run
55    /// use brevo_rust::prelude::*;
56    ///
57    /// #[tokio::main]
58    /// async fn main() {
59    ///     let config = ClientConfig {
60    ///         api_key: Some("<value>".to_string()),
61    ///         ..Default::default()
62    ///     };
63    ///     let client = BrevoClient::new(config).expect("Failed to build client");
64    ///     client
65    ///         .process
66    ///         .get_processes(
67    ///             &GetProcessesQueryRequest {
68    ///                 ..Default::default()
69    ///             },
70    ///             None,
71    ///         )
72    ///         .await;
73    /// }
74    /// ```
75    pub async fn get_processes(
76        &self,
77        request: &GetProcessesQueryRequest,
78        options: Option<RequestOptions>,
79    ) -> Result<GetProcessesResponse, ApiError> {
80        self.http_client
81            .execute_request(
82                Method::GET,
83                "processes",
84                None,
85                QueryBuilder::new()
86                    .int("limit", request.limit.clone())
87                    .int("offset", request.offset.clone())
88                    .serialize("sort", request.sort.clone())
89                    .build(),
90                options,
91            )
92            .await
93    }
94
95    /// Retrieves detailed information about a specific background process.
96    ///
97    /// **Use this to:**
98    /// - Get detailed status of a specific process
99    /// - Monitor process progress and completion
100    /// - Download results from completed export processes
101    /// - Check error details for failed processes
102    /// - Track process execution times
103    ///
104    /// **Key information returned:**
105    /// - Complete process details (ID, name, status)
106    /// - Download URLs for completed export processes
107    /// - Import details with CSV report URLs for completed import processes
108    ///
109    /// **Important considerations:**
110    /// - Process ID must exist in your account and not be deleted
111    /// - Completed export processes include download URLs
112    /// - Completed import processes include CSV report URLs with details about problematic records
113    /// - Different process types return different result structures
114    ///
115    /// # Arguments
116    ///
117    /// * `process_id` - Id of the process
118    /// * `options` - Additional request options such as headers, timeout, etc.
119    ///
120    /// # Returns
121    ///
122    /// JSON response from the API
123    ///
124    /// # Examples
125    ///
126    /// ```no_run
127    /// use brevo_rust::prelude::*;
128    ///
129    /// #[tokio::main]
130    /// async fn main() {
131    ///     let config = ClientConfig {
132    ///         api_key: Some("<value>".to_string()),
133    ///         ..Default::default()
134    ///     };
135    ///     let client = BrevoClient::new(config).expect("Failed to build client");
136    ///     client.process.get_process(1000000, None).await;
137    /// }
138    /// ```
139    pub async fn get_process(
140        &self,
141        process_id: i64,
142        options: Option<RequestOptions>,
143    ) -> Result<GetProcessResponse, ApiError> {
144        self.http_client
145            .execute_request(
146                Method::GET,
147                &format!("processes/{}", process_id),
148                None,
149                None,
150                options,
151            )
152            .await
153    }
154}