pub struct Scheduler { /* private fields */ }Expand description
A set of scheduled events, and the loop that runs them.
Implementations§
Source§impl Scheduler
impl Scheduler
pub fn new(queue: Arc<dyn Queue>) -> Self
Sourcepub fn job<J: Job>(&mut self, job: J) -> &mut ScheduledEvent
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.
Sourcepub fn push(&mut self, job: QueuedJob) -> &mut ScheduledEvent
pub fn push(&mut self, job: QueuedJob) -> &mut ScheduledEvent
Schedule an already-built envelope — a job with no Rust type behind it.
Sourcepub fn call<F>(
&mut self,
name: impl Into<String>,
task: F,
) -> &mut ScheduledEvent
pub fn call<F>( &mut self, name: impl Into<String>, task: F, ) -> &mut ScheduledEvent
Schedule a closure to run in this process. For work with no job behind it: pruning a cache, touching a heartbeat file.
pub fn events(&self) -> &[ScheduledEvent]
Sourcepub fn due_at(&self, at: i64) -> Result<Vec<String>>
pub fn due_at(&self, at: i64) -> Result<Vec<String>>
The events due at a given moment, by name. For tests and schedule:list.
Sourcepub fn next_runs_after(&self, at: i64) -> Result<Vec<(String, Option<i64>)>>
pub fn next_runs_after(&self, at: i64) -> Result<Vec<(String, Option<i64>)>>
When each event next runs after at, for schedule:list.
Sourcepub async fn tick(&self, at: i64) -> Result<TickReport>
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.
Sourcepub async fn run(&self, shutdown: Shutdown) -> Result<()>
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.