Struct clokwerk::Job [−][src]
pub struct Job<Tz = Local, Tp = ChronoTimeProvider> where
Tz: TimeZone,
Tp: TimeProvider, { /* fields omitted */ }
A job to run on the scheduler.
Create these by calling Scheduler::every()
.
Implementations
impl<Tz, Tp> Job<Tz, Tp> where
Tz: TimeZone + Sync + Send,
Tp: TimeProvider,
[src]
impl<Tz, Tp> Job<Tz, Tp> where
Tz: TimeZone + Sync + Send,
Tp: TimeProvider,
[src]pub fn at(&mut self, time: &str) -> &mut Self
[src]
Specify the time of day when a task should run, e.g.
let mut scheduler = Scheduler::new(); scheduler.every(1.day()).at("14:32").run(|| println!("Tea time!")); scheduler.every(Wednesday).at("6:32:21 PM").run(|| println!("Writing examples is hard"));
Times can be specified using strings, with or without seconds, and in either 24-hour or 12-hour time.
They can also be any other type that implements TryInto<ClokwerkTime>
, which includes chrono::NaiveTime
.
This method will panic if TryInto fails, e.g. because the time string could not be parsed.
If the value comes from an untrusted source, e.g. user input, Job::try_at
will return a result instead.
This method is mutually exclusive with Job::plus()
.
pub fn try_at(&mut self, time: &str) -> Result<&mut Self, ParseError>
[src]
Identical to Job::at
except that it returns a Result instead of panicking if the conversion failed.
let mut scheduler = Scheduler::new(); scheduler.every(1.day()).try_at("14:32")?.run(|| println!("Tea time!"));
Times can be specified with or without seconds, and in either 24-hour or 12-hour time.
Mutually exclusive with Job::plus()
.
pub fn at_time(&mut self, time: NaiveTime) -> &mut Self
[src]
Similar to Job::at
, but it takes a chrono::NaiveTime instead of a &str
.
Because it doesn’t need to parse a string, this method will always succeed.
let mut scheduler = Scheduler::new(); scheduler.every(Weekday).at_time(NaiveTime::from_hms(23, 42, 16)).run(|| println!("Also works with NaiveTime"));
pub fn plus(&mut self, ival: Interval) -> &mut Self
[src]
Add additional precision time to when a task should run, e.g.
let mut scheduler = Scheduler::new(); scheduler.every(1.day()) .plus(6.hours()) .plus(13.minutes()) .run(|| println!("Time to wake up!"));
Mutually exclusive with Job::at()
.
pub fn and_every(&mut self, ival: Interval) -> &mut Self
[src]
Add an additional scheduling to the task. All schedules will be considered when determining when the task should next run.
pub fn once(&mut self) -> &mut Self
[src]
Execute the job only once. Equivalent to _.count(1)
.
pub fn forever(&mut self) -> &mut Self
[src]
Execute the job forever. This is the default behaviour.
pub fn count(&mut self, count: usize) -> &mut Self
[src]
Execute the job only count
times.
pub fn repeating_every(&mut self, interval: Interval) -> Repeating<'_, Tz, Tp>
[src]
After running once, run again with the specified interval.
let mut scheduler = Scheduler::new(); scheduler.every(Weekday) .at("7:40") .repeating_every(10.minutes()) .times(5) .run(|| hit_snooze());
will hit snooze five times every morning, at 7:40, 7:50, 8:00, 8:10 and 8:20.
Unlike Job::at
and Job::plus
,
this affects all intervals associated with the job, not just the most recent one.
let mut scheduler = Scheduler::new(); scheduler.every(Weekday) .at("7:40") .and_every(Saturday) .at("9:15") .and_every(Sunday) .at("9:15") .repeating_every(10.minutes()) .times(5) .run(|| hit_snooze());
hits snooze five times every day, not just Sundays.
If a job is still repeating, it will ignore otherwise scheduled runs.
let mut scheduler = Scheduler::new(); scheduler.every(1.hour()) .repeating_every(45.minutes()) .times(3) .run(|| println!("Hello"));
If this is scheduled to run at 6 AM, it will print Hello
at 6:00, 6:45, and 7:30, and then again at 8:00, 8:45, 9:30, etc.
pub fn run<F>(&mut self, f: F) -> &mut Self where
F: 'static + FnMut() + Send,
[src]
F: 'static + FnMut() + Send,
Specify a task to run, and schedule its next run
pub fn is_pending(&self, now: &DateTime<Tz>) -> bool
[src]
Test whether a job is scheduled to run again. This is usually only called by Scheduler::run_pending().
pub fn execute(&mut self, now: &DateTime<Tz>)
[src]
Run a task and re-schedule it. This is usually only called by Scheduler::run_pending().
Trait Implementations
Auto Trait Implementations
impl<Tz = Local, Tp = ChronoTimeProvider> !RefUnwindSafe for Job<Tz, Tp>
impl<Tz = Local, Tp = ChronoTimeProvider> !RefUnwindSafe for Job<Tz, Tp>
impl<Tz = Local, Tp = ChronoTimeProvider> !Sync for Job<Tz, Tp>
impl<Tz = Local, Tp = ChronoTimeProvider> !Sync for Job<Tz, Tp>
impl<Tz = Local, Tp = ChronoTimeProvider> !UnwindSafe for Job<Tz, Tp>
impl<Tz = Local, Tp = ChronoTimeProvider> !UnwindSafe for Job<Tz, Tp>