ferro-queue
Background job queue system for the Ferro framework.
Features
- Redis-backed job queues
- Job delays and retries with exponential backoff
- Multiple named queues
- Concurrent job processing
- Graceful shutdown
- Environment-based configuration
Installation
Add to your Cargo.toml:
[]
= "0.1"
Or use it through the main Ferro framework which re-exports all queue types.
Configuration
From Environment Variables
use ;
// Load configuration from environment
let config = from_env;
init.await?;
Environment variables:
| Variable | Description | Default |
|---|---|---|
QUEUE_CONNECTION |
"sync" or "redis" | sync |
QUEUE_DEFAULT |
Default queue name | default |
QUEUE_PREFIX |
Redis key prefix | ferro_queue |
QUEUE_BLOCK_TIMEOUT |
Seconds to block waiting for jobs | 5 |
QUEUE_MAX_CONCURRENT |
Max concurrent jobs per worker | 10 |
REDIS_URL |
Full Redis URL (takes precedence) | - |
REDIS_HOST |
Redis host | 127.0.0.1 |
REDIS_PORT |
Redis port | 6379 |
REDIS_PASSWORD |
Redis password | - |
REDIS_DATABASE |
Redis database number | 0 |
Programmatic Configuration
use QueueConfig;
use Duration;
let config = new
.default_queue
.prefix
.max_concurrent_jobs
.block_timeout;
Defining Jobs
use ;
use ;
use async_trait;
Dispatching Jobs
// Dispatch immediately
SendEmail
.dispatch
.await?;
// Dispatch with delay
SendEmail
.delay
.dispatch
.await?;
// Dispatch to specific queue
SendEmail
.on_queue
.dispatch
.await?;
// Combine options
SendEmail
.delay
.on_queue
.dispatch
.await?;
Running Workers
use ;
// Create worker for default queue
let worker = new;
// Register job handlers
worker.;
// Run the worker (blocks until shutdown)
worker.run.await?;
Sync Mode (Development)
For development, you can use sync mode which processes jobs immediately without Redis:
QUEUE_CONNECTION=sync
Check if sync mode is enabled:
use QueueConfig;
if is_sync_mode
CLI Generator
Generate a new job with the CLI:
This creates src/jobs/send_welcome_email.rs with boilerplate code.
License
MIT