Runner-Q

A robust, scalable Redis-based activity queue and worker system for Rust applications

Powerful Features

🎯

Priority-based Processing

Support for Critical, High, Normal, and Low priority levels to ensure important tasks are processed first

Activity Scheduling

Precise timestamp-based scheduling for future execution with built-in delay support

🔄

Intelligent Retry

Built-in retry mechanism with exponential backoff for handling transient failures

💀

Dead Letter Queue

Failed activities are moved to a dead letter queue for inspection and analysis

Concurrent Processing

Configurable number of concurrent workers for optimal throughput

🎼

Activity Orchestration

Activities can execute other activities for complex workflow management

📊

Queue Statistics

Comprehensive monitoring capabilities and metrics collection

🛡️

Graceful Shutdown

Proper shutdown handling with signal support for production deployments

🗄️

Redis Persistence

Activities are stored in Redis for durability and fault tolerance

Quick Start

main.rs
use runner_q::{WorkerEngine, ActivityHandler, ActivityContext, ActivityHandlerResult};
use async_trait::async_trait;
use serde_json::json;
use std::{sync::Arc, time::Duration};

// Define your activity handler
pub struct SendEmailActivity;

#[async_trait]
impl ActivityHandler for SendEmailActivity {
    async fn handle(&self, payload: serde_json::Value, context: ActivityContext) -> ActivityHandlerResult {
        let to = payload["to"].as_str().unwrap();
        println!("Sending email to: {}", to);

        // Return success with result data
        Ok(Some(json!({"message": format!("Email sent to {}", to), "status": "delivered"})))
    }

    fn activity_type(&self) -> String {
        "send_email".to_string()
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create worker engine with builder pattern
    let engine = WorkerEngine::builder()
        .redis_url("redis://localhost:6379")
        .queue_name("my_app")
        .max_workers(8)
        .schedule_poll_interval(Duration::from_secs(30))
        .build()
        .await?;

    // Register activity handler
    engine.register_activity("send_email".to_string(), Arc::new(SendEmailActivity));

    // Get activity executor for fluent API
    let activity_executor = engine.get_activity_executor();

    // Execute an activity with custom options
    let future = activity_executor
        .activity("send_email")
        .payload(json!({"to": "user@example.com", "subject": "Welcome!"}))
        .max_retries(5)
        .timeout(Duration::from_secs(600))
        .execute()
        .await?;

    // Start the worker engine
    engine.start().await?;

    Ok(())
}

Installation

Add Runner-Q to your project with Cargo:

$ cargo add runner_q

v0.5.0

Latest Version

MIT

Open Source License

Async

Built with Tokio

Redis

Powered by Redis