elif-queue
Background job queue system for the elif.rs framework.
Features
- Multi-backend support: Memory and Redis queue backends
- Job persistence: Reliable job storage and recovery
- Priority queuing: Support for job priorities and delays
- Async-first: Built for modern async Rust applications
- Type-safe: Generic job definitions with serialization support
- Retry logic: Built-in failure handling and retry mechanisms
Quick Start
use elif_queue::{Queue, MemoryBackend, QueueConfig, Job, JobResult};
use std::time::Duration;
use serde::{Serialize, Deserialize};
use async_trait::async_trait;
#[derive(Debug, Clone, Serialize, Deserialize)]
struct EmailJob {
to: String,
subject: String,
body: String,
}
#[async_trait]
impl Job for EmailJob {
async fn execute(&self) -> JobResult<()> {
println!("Sending email to: {}", self.to);
Ok(())
}
fn job_type(&self) -> &'static str {
"email"
}
}
# tokio_test::block_on(async {
let queue = Queue::new(MemoryBackend::new(QueueConfig::default()));
let job = EmailJob {
to: "user@example.com".to_string(),
subject: "Hello".to_string(),
body: "Hello, World!".to_string(),
};
queue.enqueue(job, None).await.unwrap();
if let Some(job_entry) = queue.dequeue().await.unwrap() {
let result = job_entry.execute::<EmailJob>().await;
queue.complete(job_entry.id(), result).await.unwrap();
}
# });