batch_processing/core/
step.rs

1use std::time::SystemTime;
2use log::error;
3
4/// Represents the status of a step execution.
5#[derive(Debug, Clone)]
6pub struct StepStatus {
7    /// The step name.
8    pub name: String,
9    /// The start time of the step execution.
10    pub start_time: Option<u128>,
11    /// The end time of the step execution.
12    pub end_time: Option<u128>,
13    /// The status result of the step execution.
14    pub status: Result<String, String>,
15}
16
17pub fn throw_tolerant_exception(throw_tolerant: bool, step_name: String) -> StepStatus {
18    if throw_tolerant {
19        return StepStatus {
20            name: step_name,
21            start_time: None,
22            end_time: None,
23            status: Ok(String::from("callback is required, please provide a callback to the step")),
24        }
25    }
26    let error_message = format!("callback is required, please provide a callback to the step with name: {}", step_name);
27    error!("{}", error_message);
28    return StepStatus {
29        name: step_name,
30        start_time: None,
31        end_time: None,
32        status: Err(String::from(error_message)),
33    };
34}
35
36pub fn mount_step_status(step_name: String, step_result: Result<String, String>, start_time: u128) -> StepStatus {
37    let end_time = SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_millis();
38    return match step_result {
39        Ok(message) => StepStatus {
40            name: step_name,
41            start_time: Some(start_time),
42            end_time: Some(end_time),
43            status: Ok(message),
44        },
45        Err(message) => StepStatus {
46            name: step_name,
47            start_time: Some(start_time),
48            end_time: None,
49            status: Err(message),
50        },
51    };
52}