Skip to main content

work

Function work 

Source
pub async fn work(schedule: Schedule) -> Result<(), AppError>
Expand description

Runs forever, checking every registered task against the current time once a second (matching seconds - the cron crate’s own native precision, even though every fluent method above only offers minute-or-coarser granularity) and running whichever are due. No direct test exists for this function - the same posture larust_queue:: worker::work’s own doc comment takes; only run_due is tested.

Uses MissedTickBehavior::Skip: if a task blocks this loop for, say, 90 seconds, anything due during that window silently does not run - it is not queued up and burst-fired afterward. This matches Laravel’s own schedule:run behavior, not just a Rust-idiom default: Laravel’s own scheduler is invoked once a minute by an external cron entry with no catch-up mechanism either, if that invocation’s own process is still busy.

Running more than one process against the same app is safe only for tasks explicitly marked Schedule::on_one_server. Any other task still has no claim/lock step at all - it just checks an in-memory Schedule against the wall clock, so two xr schedule:work processes watching the same app both run every one of those due tasks, every time, silently duplicating side effects (e.g. sending the same email twice). This is the same shape Laravel itself shipped: its scheduler ran single-process-only for a long time before ->onOneServer() existed, and even now a task must opt in explicitly - nothing makes this safe by default, in either framework, because a coordinated claim costs a database round trip a genuinely single-process deployment (still the common case) shouldn’t have to pay for tasks that don’t need it.