1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! Queues: jobs that run later, outside the request that dispatched them.
//!
//! Some work, such as transcoding an uploaded podcast or sending a thousand emails, takes too long
//! to do while a request waits. This module lets you push that work to a queue and run it in a
//! worker process. To learn more, check out the
//! [queues guide](https://github.com/laravel/rust-framework/blob/0.x/docs/queues.md).
//!
//! A job is a [`Queueable`](derive@Queueable) struct with [`#[job]`](macro@job) on its `impl`
//! block. Dispatching the job pushes it to a connection, and the connection keeps the job until a
//! worker runs it:
//!
//! ```no_run
//! use laravel::container::Inject;
//! use laravel::queue::job;
//! # pub struct AudioProcessor;
//! # impl AudioProcessor { async fn process(&self, id: i64) -> laravel::Result<()> { Ok(()) } }
//!
//! #[derive(laravel::queue::Queueable)]
//! pub struct ProcessPodcast {
//! pub podcast_id: i64,
//! }
//!
//! #[job(
//! queue = "podcasts",
//! tries = 3,
//! backoff = [10.seconds(), 1.minutes()],
//! timeout = 2.minutes(),
//! )]
//! impl ProcessPodcast {
//! async fn handle(self, audio: Inject<AudioProcessor>) -> laravel::Result<()> {
//! audio.process(self.podcast_id).await
//! }
//! }
//!
//! # async fn example() -> laravel::Result<()> {
//! ProcessPodcast { podcast_id: 42 }.dispatch().await?;
//! # Ok(()) }
//! ```
//!
//! `config.queue` names the application's connections. Each connection uses the `database`,
//! `redis`, `sqs`, `cloud`, `sync`, or `discard` driver, or a driver that an application or
//! package registered with [`Drivers::extend`]. Laravel creates a connection's driver the first
//! time a job is pushed to the connection or a worker starts working it.
//!
//! # Running jobs
//!
//! Each job runs in a fresh application context that starts with the dispatching context's
//! values. Values that the job adds to its context carry on to its error reports, its `failed`
//! hook, the worker's [events] about the job, the callbacks the job triggers, and the next job in
//! its chain. The job's log lines carry a `job` span with its ID, name, connection, queue, and
//! attempt number.
//!
//! Before each run, the worker checks whether the job may still run. If the job's `retry_for` has
//! passed, or the job has no `retry_for` and has already run `tries` times, the worker fails the
//! job for good without running it.
//!
//! When a run fails, the worker fails the job for good if the job called [`Attempt::fail`], the
//! job can't be decoded, the run was the job's last, or the run used up the job's `max_errors`.
//! Otherwise, the worker retries the job after the backoff for that run's number. A release also
//! uses up a run, so a retry after a release waits as long as it would after a failed run.
//!
//! When a job fails for good, the worker removes it from its queue and stores it with the failed
//! jobs. Then the job's `failed` hook runs, the worker dispatches [`events::JobFailed`], and the
//! worker reports the job's error. A job that can't be decoded doesn't run its `failed` hook or
//! dispatch events.
//!
//! `queue:retry` pushes a failed job back onto its queue with the same ID, all of its tries, and
//! a fresh `retry_for`. When the retried job succeeds, its chain continues, and its batch stops
//! counting it as failed. A retried job on an SQS FIFO queue gets a new deduplication ID.
//!
//! # Workers
//!
//! `queue:work` fails for the `sync` and `discard` connections. When a connection's backend is
//! unavailable, the worker reports the error and tries again, doubling its wait each time up to a
//! minute. A worker started with `--stop-when-empty` exits with status 1 instead.
//!
//! When a worker is killed, its jobs stay reserved until their reservations lapse, about a minute
//! later. The interrupted run counts as an attempt and as an error toward `max_errors`.
//!
//! `queue:restart` and `queue:pause` reach workers through the default cache store. With the
//! `memory` store, `queue:restart` warns that other processes won't see the restart. With the
//! `discard` store, `queue:restart` fails. An idle worker sees a restart after its current sleep
//! or long poll, and a worker that started after the restart ignores it. While a worker can't
//! read the cache, it logs a warning, keeps working, and uses the pauses it last read.
//!
//! `queue:pause --all` is separate from pauses of single queues. `queue:continue --all` doesn't
//! resume a queue that was paused by name, and `queue:continue emails` doesn't resume `emails`
//! while every queue is paused. A worker started with `--stop-when-empty` stops when all of its
//! queues are paused.
pub use *;
pub use ;
pub use ;
/// Define a migration's `migrate` function to create the `database` queue driver's tables.
///
/// Put the macro alone in a migration file, and it creates the `jobs`, `failed_jobs`,
/// `job_batches`, and `job_batch_jobs` tables. To change the tables, replace the macro with the
/// migration the
/// [queues guide](https://github.com/laravel/rust-framework/blob/0.x/docs/queues.md#the-jobs-table) shows,
/// then edit it.
///
/// ```
/// // database/migrations/0001_01_01_000002_create_jobs_table.rs
/// laravel::queue::tables!();
/// ```
pub use queue_tables as tables;