armature-queue
Background job queue for the Armature framework.
Features
- Redis-Backed - Reliable job storage with Redis
- Priorities - Multiple priority levels
- Retries - Automatic retry with backoff
- Scheduling - Delayed job execution
- Concurrency - Multi-worker processing
- Dead Letter Queue - Failed job handling
Installation
[dependencies]
armature-queue = "0.1"
Quick Start
use armature_queue::{Queue, Worker, WorkerConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let queue = Queue::new("redis://localhost:6379", "default").await?;
queue.enqueue(
"send_email",
serde_json::json!({
"to": "user@example.com",
"subject": "Welcome!"
})
).await?;
let config = WorkerConfig { concurrency: 4, ..Default::default() };
let mut worker = Worker::with_config(queue, config);
worker
.register_handler("send_email", |job| async move {
println!("Sending email: {:?}", job.data);
Ok(())
})
.await;
worker.start().await?;
Ok(())
}
Scheduling
use chrono::{Duration, Utc};
queue.enqueue_in(
Duration::minutes(5),
"reminder",
serde_json::json!({"message": "Don't forget!"})
).await?;
queue.enqueue_at(
Utc::now() + Duration::hours(1),
"report",
serde_json::json!({})
).await?;
License
MIT OR Apache-2.0