1use simple_scheduler::{
2 Duration, Time,
3 Schedule, ScheduleAt, ScheduledTask, task,
4};
5
6use chrono::Utc;
7
8
9fn main() {
10 let periodic_task = ScheduledTask::new(
11 ScheduleAt::Interval(Duration::seconds(4)),
12 task!(async { println!("You'll see me every four seconds") })
13 ).unwrap();
14
15 let onetime_task = ScheduledTask::new(
16 ScheduleAt::DateTime(Utc::now() + Duration::seconds(15)),
17 task!(task2())
18 ).unwrap();
19
20 let daily_task = ScheduledTask::new(
21 ScheduleAt::Daily(Time::from_hms(01, 23, 45)),
22 task!(async { println!("Hello"); })
23 ).unwrap();
24
25 let schedule = Schedule::builder()
26 .tasks([
27 periodic_task,
28 onetime_task,
29 daily_task,
30 ])
31 .wake_interval(Duration::seconds(1)).unwrap()
32 .build();
33
34 schedule.run();
35
36 std::thread::sleep(Duration::seconds(30).to_std().unwrap());
38}
39
40async fn task2() {
41 println!("Function executed");
42}