Skip to main content

TaskBuilder

Struct TaskBuilder 

Source
pub struct TaskBuilder { /* private fields */ }
Expand description

Builder for configuring scheduled tasks with a fluent API

This builder is returned by Schedule::call() and allows you to configure when and how a closure-based task should run.

§Example

schedule.call(|| async {
    println!("Running task!");
    Ok(())
})
.daily()
.at("03:00")
.name("daily-task")
.description("Runs every day at 3 AM");

Implementations§

Source§

impl TaskBuilder

Source

pub fn new<F>(f: F) -> Self
where F: Fn() -> BoxedFuture<'static> + Send + Sync + 'static,

Create a new task builder with a closure

The closure should return a future that resolves to Result<(), FrameworkError>.

Source

pub fn from_async<F, Fut>(f: F) -> Self
where F: Fn() -> Fut + Send + Sync + 'static, Fut: Future<Output = TaskResult> + Send + 'static,

Create a TaskBuilder from an async closure

This is a convenience method that wraps the async closure properly.

Source

pub fn from_task<T: Task + 'static>(task: T) -> Self

Create a TaskBuilder from a struct implementing the Task trait

This allows using the fluent schedule API with struct-based tasks.

§Example
schedule.add(
    schedule.task(CleanupLogsTask::new())
        .daily()
        .at("03:00")
        .name("cleanup:logs")
);
Source

pub fn cron(self, expression: &str) -> Self

Set a custom cron expression

§Example
.cron("0 */5 * * *") // Every 5 hours at minute 0
§Panics

Panics if the cron expression is invalid.

Source

pub fn try_cron(self, expression: &str) -> Result<Self, String>

Try to set a custom cron expression, returning an error if invalid

Source

pub fn every_minute(self) -> Self

Run every minute

Source

pub fn every_two_minutes(self) -> Self

Run every 2 minutes

Source

pub fn every_five_minutes(self) -> Self

Run every 5 minutes

Source

pub fn every_ten_minutes(self) -> Self

Run every 10 minutes

Source

pub fn every_fifteen_minutes(self) -> Self

Run every 15 minutes

Source

pub fn every_thirty_minutes(self) -> Self

Run every 30 minutes

Source

pub fn hourly(self) -> Self

Run every hour at minute 0

Source

pub fn hourly_at(self, minute: u32) -> Self

Run every hour at a specific minute

§Example
.hourly_at(30) // Every hour at XX:30
Source

pub fn every_two_hours(self) -> Self

Run every 2 hours

Source

pub fn every_three_hours(self) -> Self

Run every 3 hours

Source

pub fn every_four_hours(self) -> Self

Run every 4 hours

Source

pub fn every_six_hours(self) -> Self

Run every 6 hours

Source

pub fn daily(self) -> Self

Run once daily at midnight

Source

pub fn daily_at(self, time: &str) -> Self

Run daily at a specific time

§Example
.daily_at("13:00") // Daily at 1:00 PM
Source

pub fn twice_daily(self, first_hour: u32, second_hour: u32) -> Self

Run twice daily at specific times

§Example
.twice_daily(1, 13) // At 1:00 AM and 1:00 PM
Source

pub fn at(self, time: &str) -> Self

Set the time for the current schedule

This can be chained with other methods to set a specific time.

§Example
.daily().at("14:30") // Daily at 2:30 PM
.weekly().at("09:00") // Weekly at 9:00 AM
Source

pub fn weekly(self) -> Self

Run once weekly on Sunday at midnight

Source

pub fn weekly_on(self, day: DayOfWeek) -> Self

Run weekly on a specific day at midnight

§Example
.weekly_on(DayOfWeek::Monday)
Source

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

Run on specific days of the week at midnight

§Example
.days(&[DayOfWeek::Monday, DayOfWeek::Wednesday, DayOfWeek::Friday])
Source

pub fn weekdays(self) -> Self

Run on weekdays (Monday-Friday) at midnight

Source

pub fn weekends(self) -> Self

Run on weekends (Saturday-Sunday) at midnight

Source

pub fn sundays(self) -> Self

Run on Sundays at midnight

Source

pub fn mondays(self) -> Self

Run on Mondays at midnight

Source

pub fn tuesdays(self) -> Self

Run on Tuesdays at midnight

Source

pub fn wednesdays(self) -> Self

Run on Wednesdays at midnight

Source

pub fn thursdays(self) -> Self

Run on Thursdays at midnight

Source

pub fn fridays(self) -> Self

Run on Fridays at midnight

Source

pub fn saturdays(self) -> Self

Run on Saturdays at midnight

Source

pub fn monthly(self) -> Self

Run once monthly on the first day at midnight

Source

pub fn monthly_on(self, day: u32) -> Self

Run monthly on a specific day at midnight

§Example
.monthly_on(15) // On the 15th of each month
Source

pub fn quarterly(self) -> Self

Run quarterly on the first day of each quarter at midnight

Source

pub fn yearly(self) -> Self

Run yearly on January 1st at midnight

Source

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

Set a name for this task

The name is used in logs and when listing scheduled tasks.

Source

pub fn description(self, desc: &str) -> Self

Set a description for this task

The description is shown when listing scheduled tasks.

Source

pub fn without_overlapping(self) -> Self

Prevent overlapping task runs

When enabled, the scheduler will skip running this task if a previous run is still in progress.

Source

pub fn run_in_background(self) -> Self

Run task in background (non-blocking)

When enabled, the scheduler won’t wait for the task to complete before continuing to the next task.

Auto Trait Implementations§

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<T> Chain<T> for T

Source§

fn len(&self) -> usize

The number of items that this chain link consists of.
Source§

fn append_to(self, v: &mut Vec<T>)

Append the elements in this link to the chain.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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: 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: 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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