forge_core/cron/
traits.rs1use std::future::Future;
2use std::pin::Pin;
3
4use super::context::CronContext;
5use super::schedule::CronSchedule;
6use crate::Result;
7
8pub trait ForgeCron: Send + Sync + 'static {
10 fn info() -> CronInfo;
12
13 fn execute(ctx: &CronContext) -> Pin<Box<dyn Future<Output = Result<()>> + Send + '_>>;
15}
16
17#[derive(Debug, Clone)]
19pub struct CronInfo {
20 pub name: &'static str,
22 pub schedule: CronSchedule,
24 pub timezone: &'static str,
26 pub group: &'static str,
28 pub catch_up: bool,
30 pub catch_up_limit: u32,
32 pub timeout: std::time::Duration,
34}
35
36impl Default for CronInfo {
37 fn default() -> Self {
38 Self {
39 name: "",
40 schedule: CronSchedule::default(),
41 timezone: "UTC",
42 group: "default",
43 catch_up: false,
44 catch_up_limit: 10,
45 timeout: std::time::Duration::from_secs(3600),
46 }
47 }
48}
49
50#[cfg(test)]
51#[allow(clippy::unwrap_used, clippy::indexing_slicing)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_cron_info_default() {
57 let info = CronInfo::default();
58 assert_eq!(info.name, "");
59 assert_eq!(info.timezone, "UTC");
60 assert!(!info.catch_up);
61 assert_eq!(info.catch_up_limit, 10);
62 }
63}