laravel-rust 0.1.0

Laravel for Rust: a full-stack Rust web framework, inspired by PHP Laravel
Documentation
//! 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(crate) use laravel_queue::queue::*;
#[doc(hidden)]
pub use laravel_queue::queue::{__CallbackRegistration, __Registration, __queueable};
#[doc(inline)]
pub use laravel_queue::queue::{
    Attempt, Batch, BatchId, Callback, CallbackList, Catch, ChainCatch, ChainDispatched, ConnectionDefinition, Driver,
    Drivers, Failed, Finally, HEARTBEAT, IntoBatchJob, IntoBatchJobs, IntoJobs, IntoMiddleware, Job, JobId, JobList,
    JobOptions, JobResult, JobTimedOut, JobTypes, LEASE, Middleware, MiddlewareGroup, MissingModels, Next,
    ParseIdError, PendingBatch, PendingBulk, PendingChain, PendingDispatch, Pushed, PushedBatch, QueueFake,
    QueueManager, QueueSizes, Queueable, Reservation, ReservedJob, Then, batch, bulk, callback, cancel_batch, chain,
    dispatch, dispatch_sync, events, fake, find_batch, job, manager, middleware,
};

/// 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!();
/// ```
#[cfg(feature = "database")]
pub use laravel_rust_database_macros::queue_tables as tables;