Skip to main content

Scheduler

Struct Scheduler 

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

A set of scheduled events, and the loop that runs them.

Implementations§

Source§

impl Scheduler

Source

pub fn new(queue: Arc<dyn Queue>) -> Self

Source

pub fn job<J: Job>(&mut self, job: J) -> &mut ScheduledEvent

Schedule a job. It is dispatched onto the queue when due, not run here: the scheduler’s tick must stay short, and a worker is what runs work.

The payload is taken now, when the schedule is defined, so a job that needs fresh data at run time should read it in handle rather than capture it in a field.

Source

pub fn push(&mut self, job: QueuedJob) -> &mut ScheduledEvent

Schedule an already-built envelope — a job with no Rust type behind it.

Source

pub fn call<F>( &mut self, name: impl Into<String>, task: F, ) -> &mut ScheduledEvent
where F: Fn() -> BoxFuture<'static, Result<()>> + Send + Sync + 'static,

Schedule a closure to run in this process. For work with no job behind it: pruning a cache, touching a heartbeat file.

Source

pub fn events(&self) -> &[ScheduledEvent]

Source

pub fn validate(&self) -> Result<()>

Check every expression without running anything.

Source

pub fn due_at(&self, at: i64) -> Result<Vec<String>>

The events due at a given moment, by name. For tests and schedule:list.

Source

pub fn next_runs_after(&self, at: i64) -> Result<Vec<(String, Option<i64>)>>

When each event next runs after at, for schedule:list.

Source

pub async fn tick(&self, at: i64) -> Result<TickReport>

Run everything due at at, and return without waiting for it.

Each due event is spawned rather than awaited: a scheduler that waited would be late for everything behind a slow task, which is the very thing without_overlapping exists to survive.

Source

pub async fn run(&self, shutdown: Shutdown) -> Result<()>

Run the schedule until shutdown, waking on each minute boundary.

Aligning to the boundary rather than sleeping a fixed minute is what keeps a schedule from drifting: every tick is asked about a whole minute, so an expression matches exactly once however long a tick took.

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