Skip to main content

ScheduledTask

Struct ScheduledTask 

Source
pub struct ScheduledTask<'a> { /* private fields */ }
Expand description

A task just added to the Schedule, to narrow when it runs or add hooks. It derefs to the schedule, so adding tasks can go on in a chain.

Implementations§

Source§

impl ScheduledTask<'_>

Source

pub fn weekdays(self) -> Self

Only Monday to Friday.

Source

pub fn weekends(self) -> Self

Only Saturday and Sunday.

Source

pub fn days(self, days: &[Weekday]) -> Self

Only on these days.

Source

pub fn between(self, from: &str, to: &str) -> Self

Only between two times of day (HH:MM, both included); "22:00" to "06:00" spans midnight.

Source

pub fn timezone(self, zone: &str) -> Self

Runs in this time zone instead of APP_TIMEZONE (Asia/Jakarta, +07:00, UTC).

Source

pub fn on_failure<F, Fut>(self, hook: F) -> Self
where F: Fn(Error, AppState) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,

Runs after a run fails or panics, with the error (e.g. to alert someone). The failure is logged either way.

Source

pub fn ping_before(self, url: impl Into<String>) -> Self

GETs url before each run, e.g. a health check’s “start” URL (Healthchecks.io, Cronitor, Better Stack). A failing ping is logged, never stops the task.

Source

pub fn then_ping(self, url: impl Into<String>) -> Self

GETs url after each run, however it went.

Source

pub fn ping_on_success(self, url: impl Into<String>) -> Self

GETs url after a successful run.

Source

pub fn ping_on_failure(self, url: impl Into<String>) -> Self

GETs url after a failed run.

Source

pub fn on_success<F, Fut>(self, hook: F) -> Self
where F: Fn(AppState) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,

Runs after a run succeeds.

Methods from Deref<Target = Schedule>§

Source

pub fn every<F, Fut>( &mut self, interval: Duration, name: &str, task: F, ) -> ScheduledTask<'_>
where F: Fn(AppState) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result> + Send + 'static,

Every interval, aligned to the clock (every 5 minutes runs at :00, :05, …).

Source

pub fn every_minute<F, Fut>(&mut self, name: &str, task: F) -> ScheduledTask<'_>
where F: Fn(AppState) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result> + Send + 'static,

Every minute, on the minute.

Source

pub fn every_minutes<F, Fut>( &mut self, minutes: u64, name: &str, task: F, ) -> ScheduledTask<'_>
where F: Fn(AppState) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result> + Send + 'static,

Every minutes minutes, aligned to the clock (every 15 runs at :00, :15, …).

Source

pub fn hourly<F, Fut>(&mut self, name: &str, task: F) -> ScheduledTask<'_>
where F: Fn(AppState) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result> + Send + 'static,

Every hour, on the hour.

Source

pub fn cron<F, Fut>( &mut self, expression: &str, name: &str, task: F, ) -> ScheduledTask<'_>
where F: Fn(AppState) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result> + Send + 'static,

When the wall clock matches a cron expression: minute, hour, day of month, month, day of week (0/7 or SUN), with *, a-b, lists and /step; also @hourly, @daily, @weekly, @monthly, @yearly. "30 9 * * 1-5" is 09:30 on weekdays.

Source

pub fn daily_at<F, Fut>( &mut self, time: &str, name: &str, task: F, ) -> ScheduledTask<'_>
where F: Fn(AppState) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result> + Send + 'static,

Every day at HH:MM.

Source

pub fn weekly_on<F, Fut>( &mut self, day: Weekday, time: &str, name: &str, task: F, ) -> ScheduledTask<'_>
where F: Fn(AppState) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result> + Send + 'static,

Every week on day at HH:MM.

Source

pub fn monthly_on<F, Fut>( &mut self, day: u32, time: &str, name: &str, task: F, ) -> ScheduledTask<'_>
where F: Fn(AppState) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result> + Send + 'static,

Every month on day (1–31; months without that day are skipped, so use 28 or lower for every month) at HH:MM.

Source

pub fn upcoming(&self, zone: Zone) -> Vec<UpcomingRun>

Each task with its next run (in zone unless the task has its own), as schedule:list shows them.

Source

pub async fn run_now(&self, state: AppState, name: &str) -> Result

Runs the task name now, whatever its schedule (schedule:run).

Trait Implementations§

Source§

impl Deref for ScheduledTask<'_>

Source§

type Target = Schedule

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Schedule

Dereferences the value.
Source§

impl DerefMut for ScheduledTask<'_>

Source§

fn deref_mut(&mut self) -> &mut Schedule

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for ScheduledTask<'a>

§

impl<'a> !UnwindSafe for ScheduledTask<'a>

§

impl<'a> Freeze for ScheduledTask<'a>

§

impl<'a> Send for ScheduledTask<'a>

§

impl<'a> Sync for ScheduledTask<'a>

§

impl<'a> Unpin for ScheduledTask<'a>

§

impl<'a> UnsafeUnpin for ScheduledTask<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: RngExt + ?Sized, Self: FakeBase<U>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more