Expand description
§Ferro Queue
Background job queue system for the Ferro framework.
Provides a Laravel-inspired queue system backed by the application database:
- SQLite (
BEGIN IMMEDIATE) and Postgres (FOR UPDATE SKIP LOCKED) atomic claim - Job delays, retries with full-jitter exponential backoff, and idempotency keys
- Multiple named queues processed in priority order
- Panic-isolated worker loop with SIGTERM graceful shutdown
- Tenant-scoped job execution
§Example
ⓘ
use ferro_queue::{Job, Queue, QueueConfig, WorkerLoop, WorkerConfig, Queueable};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
struct SendEmail {
to: String,
subject: String,
}
#[async_trait::async_trait]
impl Job for SendEmail {
async fn handle(&self) -> Result<(), ferro_queue::Error> {
println!("Sending email to {}: {}", self.to, self.subject);
Ok(())
}
}
// Initialise the queue at application start (once):
// Queue::init(db_connection).await?;
// Dispatch a job (sync mode by default; set QUEUE_CONNECTION=db for background):
SendEmail { to: "user@example.com".into(), subject: "Hello".into() }
.dispatch()
.await?;
// Dispatch with delay
SendEmail { to: "user@example.com".into(), subject: "Reminder".into() }
.delay(std::time::Duration::from_secs(60))
.on_queue("emails")
.dispatch()
.await?;Structs§
- Create
Jobs Table - Migration that creates the
jobstable and its indexes. - Failed
JobInfo - A failed job with the error message.
- JobInfo
- Summary of a single job for introspection.
- JobPayload
- Serialized job payload stored in the queue.
- JobRow
- A row read from the
jobstable during a claim operation. - Pending
Dispatch - A pending job dispatch.
- Queue
- Global handle to the queue’s database connection.
- Queue
Config - Queue system configuration.
- Queue
Stats - Aggregate stats across all queues.
- Single
Queue Stats - Per-queue pending/delayed counts.
- Worker
Config - Worker configuration.
- Worker
Loop - DB-backed queue worker.
Enums§
Traits§
- Job
- A job that can be executed by a queue worker.
- Queueable
- Trait for types that can be dispatched to a queue.
- Tenant
Scope Provider - Injects tenant scope around job execution.
Functions§
- claim
- Atomically claim one pending job from
queue. - delete_
job - Delete a successfully-completed job row (D-04 delete-on-success).
- dispatch
- Dispatch a job using the global queue.
- dispatch_
later - Dispatch a job with a delay.
- dispatch_
to - Dispatch a job to a specific queue.
- enqueue
- Insert a new job into the queue.
- fail_
job - Park a job as
failedwith an error message, recording the failure time. - get_
delayed_ jobs - Return up to
limitdelayed (not-yet-eligible) jobs inqueue. - get_
failed_ jobs - Return up to
limitfailed jobs (across all queues). - get_
pending_ jobs - Return up to
limitpending (immediately eligible) jobs inqueue. - get_
stats - Return aggregate pending/delayed counts per queue and the total failed count.
- reap_
startup_ claims - Park leftover
claimedrows onqueuesasfailedat worker startup. - reaper
- Re-queue claimed rows that have been held longer than
visibility_timeout. - register_
tenant_ capture_ hook - Register the tenant capture hook.
- release_
job - Reset a job to
pending, bump its attempt count, and set a newavailable_at(used by the worker after a retryable failure). - requeue_
claimed_ by - Reset all jobs claimed by
worker_idback topending(D-10 shutdown re-queue — called by the worker loop before the process exits).
Type Aliases§
- Worker
- Type alias for API continuity with callers that use the old
Workername.
Attribute Macros§
- async_
trait - Re-export async_trait for convenience