ScheduleBuilder

Struct ScheduleBuilder 

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

Builder object for a Schedule.

Implementations§

Source§

impl ScheduleBuilder

Source

pub fn task(self, task: ScheduledTask) -> Self

Add a task to the schedule.

Source

pub fn tasks(self, tasks: impl Into<Vec<ScheduledTask>>) -> Self

Add multiple tasks to the schedule.

Examples found in repository?
examples/schedule.rs (lines 26-30)
9fn main() {
10    let periodic_task = ScheduledTask::new(
11        ScheduleAt::Interval(Duration::seconds(4)),
12        task!(async { println!("You'll see me every four seconds") })
13    ).unwrap();
14
15    let onetime_task = ScheduledTask::new(
16        ScheduleAt::DateTime(Utc::now() + Duration::seconds(15)),
17        task!(task2())
18    ).unwrap();
19
20    let daily_task = ScheduledTask::new(
21        ScheduleAt::Daily(Time::from_hms(01, 23, 45)),
22        task!(async { println!("Hello"); })
23    ).unwrap();
24
25    let schedule = Schedule::builder()
26        .tasks([
27            periodic_task,
28            onetime_task,
29            daily_task,
30        ])
31        .wake_interval(Duration::seconds(1)).unwrap()
32        .build();
33
34    schedule.run();
35
36    // run() exits immediately, so we need to wait a bit.
37    std::thread::sleep(Duration::seconds(30).to_std().unwrap());
38}
Source

pub fn wake_interval(self, interval: Duration) -> Result<Self, &'static str>

Set the interval at which to check for tasks to run.

The default interval is 1 minute. The minimum is 100 nanoseconds.

Examples found in repository?
examples/schedule.rs (line 31)
9fn main() {
10    let periodic_task = ScheduledTask::new(
11        ScheduleAt::Interval(Duration::seconds(4)),
12        task!(async { println!("You'll see me every four seconds") })
13    ).unwrap();
14
15    let onetime_task = ScheduledTask::new(
16        ScheduleAt::DateTime(Utc::now() + Duration::seconds(15)),
17        task!(task2())
18    ).unwrap();
19
20    let daily_task = ScheduledTask::new(
21        ScheduleAt::Daily(Time::from_hms(01, 23, 45)),
22        task!(async { println!("Hello"); })
23    ).unwrap();
24
25    let schedule = Schedule::builder()
26        .tasks([
27            periodic_task,
28            onetime_task,
29            daily_task,
30        ])
31        .wake_interval(Duration::seconds(1)).unwrap()
32        .build();
33
34    schedule.run();
35
36    // run() exits immediately, so we need to wait a bit.
37    std::thread::sleep(Duration::seconds(30).to_std().unwrap());
38}
Source

pub fn build(self) -> Schedule

Examples found in repository?
examples/schedule.rs (line 32)
9fn main() {
10    let periodic_task = ScheduledTask::new(
11        ScheduleAt::Interval(Duration::seconds(4)),
12        task!(async { println!("You'll see me every four seconds") })
13    ).unwrap();
14
15    let onetime_task = ScheduledTask::new(
16        ScheduleAt::DateTime(Utc::now() + Duration::seconds(15)),
17        task!(task2())
18    ).unwrap();
19
20    let daily_task = ScheduledTask::new(
21        ScheduleAt::Daily(Time::from_hms(01, 23, 45)),
22        task!(async { println!("Hello"); })
23    ).unwrap();
24
25    let schedule = Schedule::builder()
26        .tasks([
27            periodic_task,
28            onetime_task,
29            daily_task,
30        ])
31        .wake_interval(Duration::seconds(1)).unwrap()
32        .build();
33
34    schedule.run();
35
36    // run() exits immediately, so we need to wait a bit.
37    std::thread::sleep(Duration::seconds(30).to_std().unwrap());
38}

Trait Implementations§

Source§

impl Default for ScheduleBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.