1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use std::{sync::Arc, time::SystemTime};
use crate::tasks::{
state::{ProcessState, TaskState},
tokio::{context::TaskExecutorContext, executor::TaskExecutor},
};
impl TaskExecutor {
/// Updates the task state and records appropriate timestamps.
///
/// Sets the new state in the shared context and updates the corresponding
/// timestamp (running_at for Running state, finished_at for Finished state).
///
/// # Arguments
///
/// * `shared_context` - The shared task execution context
/// * `new_state` - The new state to set
///
/// # Returns
///
/// The timestamp when the state change occurred
pub(crate) fn update_state(
shared_context: &Arc<TaskExecutorContext>,
new_state: TaskState,
) -> SystemTime {
shared_context.set_task_state(new_state);
let time = match new_state {
TaskState::Running => {
shared_context.set_process_state(ProcessState::Running);
shared_context.set_running_at()
}
TaskState::Finished => {
shared_context.set_process_state(ProcessState::Stopped);
shared_context.set_finished_at()
}
_ => SystemTime::now(),
};
time
}
}