Struct tokio_cron_scheduler::Job
source · [−]pub struct Job(_);
Expand description
A schedulable Job
Implementations
sourceimpl JobLocked
impl JobLocked
sourcepub fn new<S, T, E>(schedule: S, run: T) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) + Send + Sync,
S: TryInto<Schedule, Error = E>,
E: Error + 'static,
pub fn new<S, T, E>(schedule: S, run: T) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) + Send + Sync,
S: TryInto<Schedule, Error = E>,
E: Error + 'static,
Create a new cron job.
let mut sched = JobScheduler::new();
// Run at second 0 of the 15th minute of the 6th, 8th, and 10th hour
// of any day in March and June that is a Friday of the year 2017.
let job = Job::new("0 15 6,8,10 * Mar,Jun Fri 2017", |_uuid, _lock| {
println!("{:?} Hi I ran", chrono::Utc::now());
});
sched.add(job)
tokio::spawn(sched.start());
sourcepub fn new_async<S, T, E>(schedule: S, run: T) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
S: TryInto<Schedule, Error = E>,
E: Error + 'static,
pub fn new_async<S, T, E>(schedule: S, run: T) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
S: TryInto<Schedule, Error = E>,
E: Error + 'static,
Create a new async cron job.
let mut sched = JobScheduler::new();
// Run at second 0 of the 15th minute of the 6th, 8th, and 10th hour
// of any day in March and June that is a Friday of the year 2017.
let job = Job::new("0 15 6,8,10 * Mar,Jun Fri 2017", |_uuid, _lock| Box::pin( async move {
println!("{:?} Hi I ran", chrono::Utc::now());
}));
sched.add(job)
tokio::spawn(sched.start());
sourcepub fn new_cron_job<S, T, E>(
schedule: S,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) + Send + Sync,
S: TryInto<Schedule, Error = E>,
E: Error + 'static,
pub fn new_cron_job<S, T, E>(
schedule: S,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) + Send + Sync,
S: TryInto<Schedule, Error = E>,
E: Error + 'static,
Create a new cron job.
let mut sched = JobScheduler::new();
// Run at second 0 of the 15th minute of the 6th, 8th, and 10th hour
// of any day in March and June that is a Friday of the year 2017.
let job = Job::new_cron_job("0 15 6,8,10 * Mar,Jun Fri 2017", |_uuid, _lock| {
println!("{:?} Hi I ran", chrono::Utc::now());
});
sched.add(job)
tokio::spawn(sched.start());
sourcepub fn new_cron_job_async<S, T, E>(
schedule: S,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
S: TryInto<Schedule, Error = E>,
E: Error + 'static,
pub fn new_cron_job_async<S, T, E>(
schedule: S,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
S: TryInto<Schedule, Error = E>,
E: Error + 'static,
Create a new async cron job.
let mut sched = JobScheduler::new();
// Run at second 0 of the 15th minute of the 6th, 8th, and 10th hour
// of any day in March and June that is a Friday of the year 2017.
let job = Job::new("0 15 6,8,10 * Mar,Jun Fri 2017", |_uuid, _lock| Box::pin( async move {
println!("{:?} Hi I ran", chrono::Utc::now());
}));
sched.add(job)
tokio::spawn(sched.start());
sourcepub fn new_one_shot<T>(
duration: Duration,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) + Send + Sync,
pub fn new_one_shot<T>(
duration: Duration,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) + Send + Sync,
Create a new one shot job.
This is checked if it is running only after 500ms in 500ms intervals.
let mut sched = JobScheduler::new();
let job = Job::new_one_shot(Duration::from_secs(18), |_uuid, _l| {
println!("{:?} I'm only run once", chrono::Utc::now());
}
sched.add(job)
tokio::spawn(sched.start());
sourcepub fn new_one_shot_async<T>(
duration: Duration,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
pub fn new_one_shot_async<T>(
duration: Duration,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
Create a new async one shot job.
This is checked if it is running only after 500ms in 500ms intervals.
let mut sched = JobScheduler::new();
let job = Job::new_one_shot(Duration::from_secs(18), |_uuid, _l| Box::pin(async move {
println!("{:?} I'm only run once", chrono::Utc::now());
}));
sched.add(job)
tokio::spawn(sched.start());
sourcepub fn new_one_shot_at_instant<T>(
instant: Instant,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) + Send + Sync,
pub fn new_one_shot_at_instant<T>(
instant: Instant,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) + Send + Sync,
Create a new one shot job that runs at an instant
// Run after 20 seconds
let mut sched = JobScheduler::new();
let instant = std::time::Instant::now().checked_add(std::time::Duration::from_secs(20));
let job = Job::new_one_shot_at_instant(instant, |_uuid, _lock| println!("I run once after 20 seconds") );
sched.add(job)
tokio::spawn(sched.start());
sourcepub fn new_one_shot_at_instant_async<T>(
instant: Instant,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
pub fn new_one_shot_at_instant_async<T>(
instant: Instant,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
Create a new async one shot job that runs at an instant
// Run after 20 seconds
let mut sched = JobScheduler::new();
let instant = std::time::Instant::now().checked_add(std::time::Duration::from_secs(20));
let job = Job::new_one_shot_at_instant(instant, |_uuid, _lock| Box::pin(async move {println!("I run once after 20 seconds")}) );
sched.add(job)
tokio::spawn(sched.start());
sourcepub fn new_repeated<T>(
duration: Duration,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) + Send + Sync,
pub fn new_repeated<T>(
duration: Duration,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) + Send + Sync,
Create a new repeated job.
This is checked if it is running only after 500ms in 500ms intervals.
let mut sched = JobScheduler::new();
let job = Job::new_repeated(Duration::from_secs(8), |_uuid, _lock| {
println!("{:?} I'm repeated every 8 seconds", chrono::Utc::now());
}
sched.add(job)
tokio::spawn(sched.start());
sourcepub fn new_repeated_async<T>(
duration: Duration,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
pub fn new_repeated_async<T>(
duration: Duration,
run: T
) -> Result<Self, JobSchedulerError> where
T: 'static,
T: FnMut(Uuid, JobsSchedulerLocked) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync,
Create a new async repeated job.
This is checked if it is running only after 500ms in 500ms intervals.
let mut sched = JobScheduler::new();
let job = Job::new_repeated(Duration::from_secs(8), |_uuid, _lock| Box::pin(async move {
println!("{:?} I'm repeated every 8 seconds", chrono::Utc::now());
}));
sched.add(job)
tokio::spawn(sched.start());
sourcepub fn tick(&mut self) -> Result<bool, JobSchedulerError>
pub fn tick(&mut self) -> Result<bool, JobSchedulerError>
The tick
method returns a true if there was an invocation needed after it was last called
This method will also change the last tick on itself
sourcepub fn on_notifications_add(
&self,
job_scheduler: &JobsSchedulerLocked,
run: Box<OnJobNotification>,
states: Vec<JobState>
) -> Result<Uuid, JobSchedulerError>
pub fn on_notifications_add(
&self,
job_scheduler: &JobsSchedulerLocked,
run: Box<OnJobNotification>,
states: Vec<JobState>
) -> Result<Uuid, JobSchedulerError>
Add a notification to run on a list of state notifications
sourcepub fn on_start_notification_add(
&self,
job_scheduler: &JobsSchedulerLocked,
on_start: Box<OnJobNotification>
) -> Result<Uuid, JobSchedulerError>
pub fn on_start_notification_add(
&self,
job_scheduler: &JobsSchedulerLocked,
on_start: Box<OnJobNotification>
) -> Result<Uuid, JobSchedulerError>
Run something when the task is started. Returns a UUID as handle for this notification. This
UUID needs to be used when you want to remove the notification handle using on_start_notification_remove
.
sourcepub fn on_notification_removal(
&self,
job_scheduler: &JobsSchedulerLocked,
notification_id: &Uuid,
states: Option<Vec<JobState>>
) -> Result<(Uuid, bool), JobSchedulerError>
pub fn on_notification_removal(
&self,
job_scheduler: &JobsSchedulerLocked,
notification_id: &Uuid,
states: Option<Vec<JobState>>
) -> Result<(Uuid, bool), JobSchedulerError>
Remove a notification optionally for a certain type of states
sourcepub fn on_start_notification_remove(
&self,
job_scheduler: &JobsSchedulerLocked,
notification_id: &Uuid
) -> Result<bool, JobSchedulerError>
pub fn on_start_notification_remove(
&self,
job_scheduler: &JobsSchedulerLocked,
notification_id: &Uuid
) -> Result<bool, JobSchedulerError>
Remove the notification when the task was started. Uses the same UUID that was returned by
on_start_notification_add
sourcepub fn on_done_notification_add(
&mut self,
job_scheduler: &JobsSchedulerLocked,
on_stop: Box<OnJobNotification>
) -> Result<Uuid, JobSchedulerError>
pub fn on_done_notification_add(
&mut self,
job_scheduler: &JobsSchedulerLocked,
on_stop: Box<OnJobNotification>
) -> Result<Uuid, JobSchedulerError>
Run something when the task is stopped. Returns a UUID as handle for this notification. This
UUID needs to be used when you want to remove the notification handle using on_stop_notification_remove
.
sourcepub fn on_done_notification_remove(
&mut self,
job_scheduler: &JobsSchedulerLocked,
notification_id: &Uuid
) -> Result<bool, JobSchedulerError>
pub fn on_done_notification_remove(
&mut self,
job_scheduler: &JobsSchedulerLocked,
notification_id: &Uuid
) -> Result<bool, JobSchedulerError>
Remove the notification when the task was stopped. Uses the same UUID that was returned by
on_done_notification_add
sourcepub fn on_removed_notification_add(
&mut self,
job_scheduler: &JobsSchedulerLocked,
on_removed: Box<OnJobNotification>
) -> Result<Uuid, JobSchedulerError>
pub fn on_removed_notification_add(
&mut self,
job_scheduler: &JobsSchedulerLocked,
on_removed: Box<OnJobNotification>
) -> Result<Uuid, JobSchedulerError>
Run something when the task was removed. Returns a UUID as handle for this notification. This
UUID needs to be used when you want to remove the notification handle using on_removed_notification_remove
.
sourcepub fn on_removed_notification_remove(
&mut self,
job_scheduler: &JobsSchedulerLocked,
notification_id: &Uuid
) -> Result<bool, JobSchedulerError>
pub fn on_removed_notification_remove(
&mut self,
job_scheduler: &JobsSchedulerLocked,
notification_id: &Uuid
) -> Result<bool, JobSchedulerError>
Remove the notification when the task was removed. Uses the same UUID that was returned by
on_removed_notification_add
sourcepub fn on_stop_notification_add(
&mut self,
job_scheduler: &JobsSchedulerLocked,
on_removed: Box<OnJobNotification>
) -> Result<Uuid, JobSchedulerError>
pub fn on_stop_notification_add(
&mut self,
job_scheduler: &JobsSchedulerLocked,
on_removed: Box<OnJobNotification>
) -> Result<Uuid, JobSchedulerError>
Run something when the task was removed. Returns a UUID as handle for this notification. This
UUID needs to be used when you want to remove the notification handle using on_removed_notification_remove
.
sourcepub fn on_stop_notification_remove(
&mut self,
job_scheduler: &JobsSchedulerLocked,
notification_id: &Uuid
) -> Result<bool, JobSchedulerError>
pub fn on_stop_notification_remove(
&mut self,
job_scheduler: &JobsSchedulerLocked,
notification_id: &Uuid
) -> Result<bool, JobSchedulerError>
Remove the notification when the task was removed. Uses the same UUID that was returned by
on_removed_notification_add
sourcepub fn set_job_data(
&mut self,
job_data: JobStoredData
) -> Result<(), JobSchedulerError>
pub fn set_job_data(
&mut self,
job_data: JobStoredData
) -> Result<(), JobSchedulerError>
Override the job’s data for use in data storage
sourcepub fn set_stop(&mut self, stop: bool) -> Result<(), JobSchedulerError>
pub fn set_stop(&mut self, stop: bool) -> Result<(), JobSchedulerError>
Set whether this job has been stopped
sourcepub fn job_data(&mut self) -> Result<JobStoredData, JobSchedulerError>
pub fn job_data(&mut self) -> Result<JobStoredData, JobSchedulerError>
Get the job data
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for JobLocked
impl Send for JobLocked
impl Sync for JobLocked
impl Unpin for JobLocked
impl UnwindSafe for JobLocked
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more