pub struct ScheduleBuilder { /* private fields */ }
Expand description
Builder object for a Schedule.
Implementations§
Source§impl ScheduleBuilder
impl ScheduleBuilder
Sourcepub fn task(self, task: ScheduledTask) -> Self
pub fn task(self, task: ScheduledTask) -> Self
Add a task to the schedule.
Sourcepub fn tasks(self, tasks: impl Into<Vec<ScheduledTask>>) -> Self
pub fn tasks(self, tasks: impl Into<Vec<ScheduledTask>>) -> Self
Add multiple tasks to the schedule.
Examples found in repository?
examples/schedule.rs (lines 26-30)
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 // run() exits immediately, so we need to wait a bit.
37 std::thread::sleep(Duration::seconds(30).to_std().unwrap());
38}
Sourcepub fn wake_interval(self, interval: Duration) -> Result<Self, &'static str>
pub fn wake_interval(self, interval: Duration) -> Result<Self, &'static str>
Set the interval at which to check for tasks to run.
The default interval is 1 minute. The minimum is 100 nanoseconds.
Examples found in repository?
examples/schedule.rs (line 31)
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 // run() exits immediately, so we need to wait a bit.
37 std::thread::sleep(Duration::seconds(30).to_std().unwrap());
38}
Sourcepub fn build(self) -> Schedule
pub fn build(self) -> Schedule
Examples found in repository?
examples/schedule.rs (line 32)
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 // run() exits immediately, so we need to wait a bit.
37 std::thread::sleep(Duration::seconds(30).to_std().unwrap());
38}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ScheduleBuilder
impl !RefUnwindSafe for ScheduleBuilder
impl Send for ScheduleBuilder
impl !Sync for ScheduleBuilder
impl Unpin for ScheduleBuilder
impl !UnwindSafe for ScheduleBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more