1mod async_handler;
2mod async_job;
3mod jobschedule;
4mod sync_handler;
5mod sync_job;
6pub use self::async_handler::AsyncHandler;
7pub use self::async_job::{AsyncJob, AsyncJobBuilder};
8pub use self::jobschedule::JobScheduleBuilder;
9pub use self::sync_handler::SyncHandler;
10pub use self::sync_job::{SyncJob, SyncJobBuilder};
11use crate::{extensions::Extensions, interval::Interval, prelude::TimeUnits};
12use chrono::TimeZone;
13
14pub trait Job<Tz>
15where
16 Tz: TimeZone,
17{
18 fn box_clone(&self) -> Box<dyn Job<Tz> + Send>;
19
20 fn start_schedule(&self, e: Extensions, tz: Tz);
22}
23
24pub trait JobBuilder<Args> {
25 fn new() -> Self;
27
28 fn and(&mut self) -> &mut Self;
30
31 fn repeat_seq(&mut self, n: u32, interval: Interval) -> &mut Self;
33
34 fn repeat_async(&mut self, n: u32, interval: Interval) -> &mut Self;
36
37 fn get_mut_cron_builder(&mut self) -> &mut JobScheduleBuilder;
39
40 fn at(&mut self, interval: Interval) -> &mut Self {
42 self.get_mut_cron_builder().at(interval);
43 self
44 }
45
46 fn since_every(&mut self, start: Interval, interval: Interval) -> &mut Self {
48 self.get_mut_cron_builder().since_every(start, interval);
49 self
50 }
51
52 fn every(&mut self, interval: Interval) -> &mut Self {
54 self.get_mut_cron_builder().every(interval);
55 self
56 }
57
58 fn from_to(&mut self, start: Interval, end: Interval) -> &mut Self {
60 self.get_mut_cron_builder().from_to(start, end);
61 self
62 }
63
64 fn at_datetime(
66 &mut self,
67 year: Option<i32>,
68 month: Option<u32>,
69 day: Option<u32>,
70 hour: Option<u32>,
71 min: Option<u32>,
72 sec: Option<u32>,
73 ) -> &mut Self {
74 year.map(|x| self.at((x as u32).year()));
75 month.map(|x| self.at((x as u32).month()));
76 day.map(|x| self.at((x as u32).day()));
77 hour.map(|x| self.at((x as u32).hour()));
78 min.map(|x| self.at((x as u32).minute()));
79 sec.map(|x| self.at((x as u32).second()));
80 self
81 }
82
83 fn at_time(&mut self, hour: u32, min: u32, sec: u32) -> &mut Self {
85 self.at_datetime(None, None, None, Some(hour), Some(min), Some(sec));
86 self
87 }
88
89 fn at_date(&mut self, year: i32, month: u32, day: u32) -> &mut Self {
91 self.at_datetime(Some(year), Some(month), Some(day), None, None, None);
92 self
93 }
94
95 fn get_mut_since(&mut self) -> &mut (i32, u32, u32, u32, u32, u32);
96
97 fn since_datetime(
99 &mut self,
100 year: i32,
101 month: u32,
102 day: u32,
103 hour: u32,
104 min: u32,
105 sec: u32,
106 ) -> &mut Self {
107 *(self.get_mut_since()) = (year, month, day, hour, min, sec);
108 self
109 }
110
111 fn since_date(&mut self, year: i32, month: u32, day: u32) -> &mut Self {
113 self.get_mut_since().0 = year;
114 self.get_mut_since().1 = month;
115 self.get_mut_since().2 = day;
116 self
117 }
118
119 fn since_time(&mut self, hour: u32, min: u32, sec: u32) -> &mut Self {
121 self.get_mut_since().3 = hour;
122 self.get_mut_since().4 = min;
123 self.get_mut_since().5 = sec;
124 self
125 }
126
127 fn after(&mut self, delay: u64) -> &mut Self {
129 self.get_mut_cron_builder().add_delay(delay);
130 self
131 }
132}