persistent_scheduler/core/
task_kind.rs

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
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
/// Defines the type of task to be executed.
pub enum TaskKind {
    /// Represents a cron job, which is scheduled to run at specific intervals.
    Cron {
        /// Schedule expression for Cron tasks.
        schedule: String,
        /// Timezone for the schedule expression.
        timezone: String,
    },

    /// Represents a repeated job that runs at a regular interval.
    Repeat {
        /// Repeat interval for Repeat tasks, in seconds.
        interval_seconds: u32
    },

    /// Represents a one-time job that runs once and then completes.
    #[default]
    Once,
}

impl std::fmt::Display for TaskKind {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            TaskKind::Cron { .. } => write!(f, "Cron"),
            TaskKind::Repeat { .. } => write!(f, "Repeat"),
            TaskKind::Once => write!(f, "Once"),
        }
    }
}