Expand description
§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<()> {
// Send email logic here
println!("Sending email to: {}", self.to);
Ok(())
}
fn job_type(&self) -> &'static str {
"email"
}
}
// Create a memory-based queue
let queue = Queue::new(MemoryBackend::new(QueueConfig::default()));
// Enqueue a job
let job = EmailJob {
to: "user@example.com".to_string(),
subject: "Hello".to_string(),
body: "Hello, World!".to_string(),
};
queue.enqueue(job, None).await.unwrap();
// Process jobs
if let Some(job_entry) = queue.dequeue().await.unwrap() {
let result = job_entry.execute::<EmailJob>().await;
queue.complete(job_entry.id(), result).await.unwrap();
}Re-exports§
Modules§
- backends
- Queue backend implementations
- config
- Queue configuration types and builders
- scheduler
- Job scheduling system with cron expression support
- worker
- Worker implementation for processing jobs from the queue
Structs§
- JobEntry
- Job entry containing job data and metadata
- Queue
- High-level queue interface
- Queue
Stats - Queue statistics
Enums§
- JobState
- Job execution state
- Priority
- Job priority levels
- Queue
Error - Job execution errors
Traits§
- Job
- Core trait that all jobs must implement
- Queue
Backend - Core queue backend trait that all queue implementations must implement
Type Aliases§
- JobId
- Job unique identifier
- JobResult
- Result type for job execution
- Queue
Result - Result type for queue operations