Expand description
§Backfill
A high-performance, PostgreSQL-backed async priority queue system for Rust applications. Built on top of Graphile Worker for reliability and performance.
This library provides:
- Durable job queues with PostgreSQL backend
- Priority-based scheduling with configurable priority levels
- Parallel execution by default - jobs run concurrently across all workers
- Serial queues when you need ordering or rate limiting
- Exponential backoff with jitter to prevent thundering herds
- Flexible retry policies (fast, aggressive, conservative, or custom)
- Dead letter queue handling for failed jobs
- Type-safe job handlers using Rust’s type system
- Low-latency execution via PostgreSQL LISTEN/NOTIFY
§Quick Start
use backfill::{BackfillClient, enqueue_critical, enqueue_fast_with_retries, JobSpec, RetryPolicy};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct SendEmailJob {
recipient: String,
subject: String,
body: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let database_url = "postgresql://user:password@localhost/mydb";
let client = BackfillClient::new(database_url).await?;
// Enqueue a critical job with aggressive retry policy (12 attempts)
enqueue_critical(
&client,
"send_email",
&SendEmailJob {
recipient: "user@example.com".to_string(),
subject: "Welcome!".to_string(),
body: "Thanks for signing up.".to_string(),
},
Some("welcome_email_123".to_string()),
).await?;
// Or use fast retries for quick turnaround (3 attempts, 100ms-30s)
enqueue_fast_with_retries(
&client,
"send_notification",
&SendEmailJob {
recipient: "admin@example.com".to_string(),
subject: "Notification".to_string(),
body: "Quick notification with fast retries.".to_string(),
},
Some("quick_notification".to_string()),
).await?;
Ok(())
}Modules§
- cleanup
- Cleanup utilities for maintaining worker queue health
- metrics
- Metrics emission for observability
Structs§
- After
JobRun - After
JobRun Context - Backfill
Client - High-level client for the backfill job queue system.
- Before
JobRun - Before
JobRun Context - Before
JobSchedule - Before
JobSchedule Context - Cron
JobScheduled - Cron
JobScheduled Context - Cron
Tick - Cron
Tick Context - Crontab
Parse Error - DlqCleanup
Plugin - Plugin that cleans up DLQ entries when jobs with matching job_keys complete.
- DlqFilter
- Filter parameters for querying DLQ jobs.
- DlqJob
- A job that has been moved to the dead letter queue after failing permanently.
- DlqJob
List - Paginated list of DLQ jobs.
- DlqStats
- Statistics about the dead letter queue.
- Hook
Registry - Job
JobextendsDbJobwith an additional task_identifier field.- JobComplete
- JobComplete
Context - JobFail
- JobFail
Context - JobFetch
- JobFetch
Context - JobPermanently
Fail - JobPermanently
Fail Context - JobSpec
- Configuration for job scheduling and execution.
- JobStart
- JobStart
Context - Priority
- Priority levels for jobs in the backfill system.
- Queue
Config - Configuration for a worker queue
- Retry
Policy - Configuration for exponential backoff retry policy.
- Worker
Config - Flexible worker configuration for integration with existing applications
- Worker
Context - Context provided to task handlers when processing a job.
- Worker
Init - Worker
Init Context - Worker
Options - Configuration options for initializing a Graphile Worker instance.
- Worker
Options Builder - Cloneable wrapper around WorkerOptions configuration
- Worker
Runner - Reusable worker runner for flexible integration patterns
- Worker
Runner Builder - Builder for WorkerRunner that allows configuring job types and plugins
- Worker
Shutdown - Worker
Shutdown Context - Worker
Start - Worker
Start Context
Enums§
- Backfill
Error - Core errors for the Backfill library
- Enqueue
Outcome - Outcome of an enqueue operation.
- Hook
Result - JobKey
Mode - JobSchedule
Result - Queue
- Queue configuration for job execution.
- Shutdown
Reason - Worker
Error - Worker-specific errors that can classify whether jobs should be retried
Constants§
- DEFAULT_
STALE_ JOB_ LOCK_ TIMEOUT - Default timeout for considering a job lock stale.
- DEFAULT_
STALE_ LOCK_ CLEANUP_ INTERVAL - Default interval for periodic stale lock cleanup.
- DEFAULT_
STALE_ QUEUE_ LOCK_ TIMEOUT - Default timeout for considering a queue lock stale.
Traits§
- Into
Task Handler Result - Trait for converting task handler return types into a standardized Result.
- Plugin
- Task
Handler - Core trait for defining task handlers in Graphile Worker.
Functions§
- enqueue_
bulk - Enqueue a normal-priority job for parallel execution.
- enqueue_
bulk_ with_ retries - Enqueue a bulk job with conservative exponential backoff retries.
- enqueue_
critical - Enqueue a critical job with aggressive exponential backoff retries.
- enqueue_
emergency - Enqueue an emergency priority job.
- enqueue_
fast - Enqueue a high-priority job for parallel execution.
- enqueue_
fast_ with_ retries - Enqueue a high-priority job with fast exponential backoff retries.
- enqueue_
serial - Enqueue a job for serial execution within a named queue.
- parse_
crontab - Parse a crontab definition into a Vec of crontab