Expand description
A durable job queue - Laravel’s dispatch(new Job)/queue:work.
Unlike larust-events (in-process, synchronous, no persistence), a
Job survives the current request and even a process restart:
dispatch() enqueues it durably; a separate xr queue:work process
(backed by work()) claims and executes jobs until stopped.
Backed by SQL-family storage (Config::queue_driver == "database", the
default) or Redis ("redis") - see dispatch/[worker]’s own doc
comments for the dispatch shape, and [sql_worker]/[redis_worker]
for the two claim/lease/retry implementations.
Structs§
- JobRegistry
- Maps a
Job::JOB_TYPEtag back to the concrete type that can deserialize and run it - built fresh by whatever callswork()(typically the generated app’s ownqueue:workbranch inmain.rs), not a process-wide static: only onework()loop reads it, in the one process running it, so there’s no cross-request sharing need the waylarust-events’ listener registry orlarust_http::route’s named-route registry have.
Traits§
- Job
- A unit of deferred work. Implemented once per job type, the same
“app implements this once per thing” shape as
Policy<U>/Mailable.
Functions§
- dispatch
- Serializes
jobto JSON and enqueues it - durable the moment this returnsOk, independent of whether anyxr queue:workprocess is currently running to pick it up. - prune_
failed_ jobs - Deletes/trims old entries from whichever
failed_jobsstore [crate::queue_driver] selects - see the two backend-specific implementations’ own doc comments for the exact retention policy each uses (time-based for SQL, count-based for Redis). - work
- Runs forever, claiming and executing jobs one at a time until the
process is stopped (Ctrl+C / killed - no signal handling here, same as
Laravel’s own
queue:workwithout--stop-when-empty). A job whose handler fails, or whosejob_typehas no registered handler, is recorded as a failure rather than retried forever or silently dropped.