Struct clokwerk::Scheduler [−][src]
pub struct Scheduler<Tz = Local, Tp = ChronoTimeProvider> where
Tz: TimeZone,
Tp: TimeProvider, { /* fields omitted */ }
Job scheduler
Implementations
impl Scheduler
[src]
impl Scheduler
[src]pub fn new() -> Self
[src]
Create a new scheduler. Dates and times will be interpretted using the local timezone
pub fn with_tz<Tz: TimeZone>(tz: Tz) -> Scheduler<Tz>
[src]
Create a new scheduler. Dates and times will be interpretted using the specified timezone.
pub fn with_tz_and_provider<Tz: TimeZone, Tp: TimeProvider>(
tz: Tz
) -> Scheduler<Tz, Tp>
[src]
tz: Tz
) -> Scheduler<Tz, Tp>
Create a new scheduler. Dates and times will be interpretted using the specified timezone. In addition, you can provide an alternate time provider. This is mostly useful for writing tests.
impl<Tz, Tp> Scheduler<Tz, Tp> where
Tz: TimeZone + Sync + Send,
Tp: TimeProvider,
[src]
impl<Tz, Tp> Scheduler<Tz, Tp> where
Tz: TimeZone + Sync + Send,
Tp: TimeProvider,
[src]pub fn every(&mut self, ival: Interval) -> &mut Job<Tz, Tp>
[src]
Add a new job to the scheduler to be run on the given interval
let mut scheduler = Scheduler::new(); scheduler.every(10.minutes()).plus(30.seconds()).run(|| println!("Periodic task")); scheduler.every(1.day()).at("3:20 pm").run(|| println!("Daily task")); scheduler.every(Wednesday).at("14:20:17").run(|| println!("Weekly task")); scheduler.every(Weekday).run(|| println!("Every weekday at midnight"));
pub fn run_pending(&mut self)
[src]
Run all jobs that should run at this time.
This method blocks while jobs are being run. If a job takes a long time, it may prevent other tasks from running as scheduled. If you have a long-running task, you might consider having the job move the work into another thread so that it can return promptly.
use std::thread; use std::time::Duration; loop { scheduler.run_pending(); thread::sleep(Duration::from_millis(100)); }
impl<Tz> Scheduler<Tz> where
Tz: TimeZone + Sync + Send + 'static,
<Tz as TimeZone>::Offset: Send,
[src]
impl<Tz> Scheduler<Tz> where
Tz: TimeZone + Sync + Send + 'static,
<Tz as TimeZone>::Offset: Send,
[src]#[must_use = "The scheduler is halted when the returned handle is dropped"]pub fn watch_thread(self, frequency: Duration) -> ScheduleHandle
[src]
Start a background thread to call Scheduler::run_pending() repeatedly. The frequency argument controls how long the thread will sleep between calls to Scheduler::run_pending(). If the returned ScheduleHandle is dropped, the resulting thread will end cleanly when Scheduler::run_pending() would have next been called.
Passing large durations for frequency
can cause long delays when ScheduleHandle::stop()
is called, or the ScheduleHandle is dropped, as it waits for the thread to finish sleeping.
This could affect how long it takes for the program to exit.
Reasonable values for frequency
would be between 100 ms and 10 seconds.
If in doubt, choose a smaller value.
Trait Implementations
Auto Trait Implementations
impl<Tz = Local, Tp = ChronoTimeProvider> !RefUnwindSafe for Scheduler<Tz, Tp>
impl<Tz = Local, Tp = ChronoTimeProvider> !RefUnwindSafe for Scheduler<Tz, Tp>
impl<Tz = Local, Tp = ChronoTimeProvider> !Sync for Scheduler<Tz, Tp>
impl<Tz = Local, Tp = ChronoTimeProvider> !Sync for Scheduler<Tz, Tp>
impl<Tz, Tp> Unpin for Scheduler<Tz, Tp> where
Tp: Unpin,
Tz: Unpin,
<Tz as TimeZone>::Offset: Unpin,
impl<Tz, Tp> Unpin for Scheduler<Tz, Tp> where
Tp: Unpin,
Tz: Unpin,
<Tz as TimeZone>::Offset: Unpin,
impl<Tz = Local, Tp = ChronoTimeProvider> !UnwindSafe for Scheduler<Tz, Tp>
impl<Tz = Local, Tp = ChronoTimeProvider> !UnwindSafe for Scheduler<Tz, Tp>