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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Event types for the scheduler.
use crate::schedule::Schedule;
use serde::{Deserialize, Serialize};
/// Events emitted by the scheduler.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum SchedulerEvent {
/// A task was scheduled.
TaskScheduled {
/// Unique identifier for the task.
task_id: String,
/// Type of task (used to look up handler).
task_type: String,
/// Schedule configuration.
schedule: Schedule,
/// Task payload (serialized task data).
payload: Vec<u8>,
/// Maximum number of retries on failure.
max_retries: u32,
/// Timeout in seconds.
timeout_secs: u64,
},
/// A task was executed.
TaskExecuted {
/// Task identifier.
task_id: String,
/// Unique execution identifier.
execution_id: String,
/// Event ID of the event triggered by this execution (0 if failed).
triggered_event_id: u64,
/// When execution started (Unix timestamp).
started_at: i64,
/// When execution completed (Unix timestamp).
completed_at: i64,
/// Whether execution succeeded.
success: bool,
/// Error message if execution failed.
error: Option<String>,
},
/// A task was cancelled.
TaskCancelled {
/// Task identifier.
task_id: String,
/// Reason for cancellation.
reason: String,
},
}
impl SchedulerEvent {
/// Returns the task ID for this event.
pub fn task_id(&self) -> &str {
match self {
Self::TaskScheduled { task_id, .. }
| Self::TaskExecuted { task_id, .. }
| Self::TaskCancelled { task_id, .. } => task_id,
}
}
}