tako_rs_core/queue.rs
1//! In-memory background job queue with named queues, retry policies, and dead letter support.
2//!
3//! Provides a lightweight task queue for deferring work to background workers —
4//! useful for sending emails, webhooks, async processing, etc.
5//!
6//! # Features
7//!
8//! - **Named queues** — separate logical channels (e.g. `"email"`, `"webhook"`)
9//! - **Configurable workers** — per-queue concurrency limit
10//! - **Retry policy** — fixed or exponential backoff with max attempts
11//! - **Delayed jobs** — schedule execution after a duration
12//! - **Dead letter queue** — failed jobs stored for inspection
13//! - **Graceful shutdown** — drain in-flight jobs before exit
14//!
15//! # Examples
16//!
17//! ```rust,no_run
18//! use tako::queue::{Queue, RetryPolicy, Job};
19//! use std::time::Duration;
20//!
21//! # async fn example() {
22//! let queue = Queue::builder()
23//! .workers(4)
24//! .retry(RetryPolicy::exponential(3, Duration::from_secs(1)))
25//! .build();
26//!
27//! queue.register("send_email", |job: Job| async move {
28//! let to: String = job.deserialize()?;
29//! println!("Sending email to {to}");
30//! Ok(())
31//! });
32//!
33//! queue.push("send_email", &"user@example.com").await.unwrap();
34//! # }
35//! ```
36
37/// Pluggable queue backend abstraction (v2). The bundled `Queue` keeps its
38/// in-process semantics; opt into a remote broker via [`backend::QueueBackend`].
39pub mod backend;
40
41/// Builder for configuring a [`Queue`].
42mod builder;
43
44/// Cron scheduling on top of `QueueBackend` (opt-in via `queue-cron` feature).
45#[cfg(feature = "queue-cron")]
46#[cfg_attr(docsrs, doc(cfg(feature = "queue-cron")))]
47pub mod cron;
48
49/// Error type for queue operations.
50mod error;
51
52/// Job and dead-letter task types.
53mod job;
54
55/// Retry/backoff configuration.
56mod retry;
57
58/// Queue runtime: builder and lifecycle handles.
59mod runtime;
60
61/// Queue signal ids and emission helper.
62#[cfg(feature = "signals")]
63mod signals;
64
65/// Background worker loop draining pending jobs.
66mod worker;
67
68pub use builder::QueueBuilder;
69pub use error::QueueError;
70pub use job::DeadJob;
71pub use job::Job;
72pub use retry::RetryPolicy;
73pub use runtime::Queue;
74#[cfg(feature = "signals")]
75pub(crate) use signals::emit_queue_signal;
76#[cfg(feature = "signals")]
77pub use signals::signal_ids;