Hammerwork
A high-performance, database-driven job queue for Rust with comprehensive features for production workloads.
Features
- ๐ Job Encryption & PII Protection: Enterprise-grade encryption for sensitive job payloads with AES-256-GCM and ChaCha20-Poly1305, field-level PII protection, and configurable retention policies
- ๐๏ธ Advanced Key Management: Complete key lifecycle management with master key encryption, automatic rotation, audit trails, and external KMS integration
- ๐ Dynamic Job Spawning: Jobs can dynamically create child jobs during execution for fan-out processing patterns; children record their parent as a dependency
- ๐ Web Dashboard: Modern real-time web interface for monitoring queues, managing jobs, and system administration with authentication and WebSocket updates
- ๐งช TestQueue Framework: Complete in-memory testing implementation with MockClock for deterministic testing of time-dependent features, workflows, and job processing
- ๐ Job Tracing & Correlation: Comprehensive distributed tracing with OpenTelemetry integration, trace IDs, correlation IDs, and lifecycle event hooks
- ๐ Job Dependencies & Workflows: Create complex data processing pipelines with job dependencies, sequential chains, and parallel processing with synchronization barriers
- ๐๏ธ Job Archiving & Retention: Policy-driven archival with configurable retention periods, payload compression, and automated cleanup for compliance and performance
- Multi-database support: PostgreSQL and MySQL backends with optimized dependency queries
- Advanced retry strategies: Exponential backoff, linear, Fibonacci, and custom retry patterns with jitter
- Job prioritization: Five priority levels with weighted and strict scheduling algorithms
- Result storage: Database and in-memory result storage with TTL and automatic cleanup
- Worker autoscaling: Dynamic worker pool scaling based on queue depth and configurable thresholds
- Batch operations: High-performance bulk job enqueuing with optimized worker processing
- Cron scheduling: Full cron expression support with timezone awareness
- Rate limiting: Token bucket rate limiting with configurable burst limits
- Monitoring: Prometheus metrics and advanced alerting (enabled by default)
- Job timeouts: Per-job and worker-level timeout configuration
- Statistics: Comprehensive job statistics and dead job management
- Async/await: Built on Tokio for high concurrency
- Type-safe: Leverages Rust's type system for reliability
Installation
Core Library
[]
# Default features include metrics and alerting
= { = "2.0", = ["postgres"] }
# or
= { = "2.0", = ["mysql"] }
# With encryption for PII protection
= { = "2.0", = ["postgres", "encryption"] }
# With AWS KMS integration for enterprise key management
= { = "2.0", = ["postgres", "encryption", "aws-kms"] }
# With Google Cloud KMS integration for enterprise key management
= { = "2.0", = ["postgres", "encryption", "gcp-kms"] }
# With HashiCorp Vault KMS integration for enterprise key management
= { = "2.0", = ["postgres", "encryption", "vault-kms"] }
# With distributed tracing
= { = "2.0", = ["postgres", "tracing"] }
# Full feature set
= { = "2.0", = ["postgres", "encryption", "aws-kms", "gcp-kms", "vault-kms", "tracing"] }
# Minimal installation
= { = "2.0", = ["postgres"], = false }
Feature Flags: postgres, mysql, metrics (default), alerting (default), encryption (optional), aws-kms (optional), gcp-kms (optional), vault-kms (optional), tracing (optional), test (for TestQueue)
Web Dashboard (Optional)
# Install the web dashboard
# Or add to your project
Start the dashboard:
# Dashboard available at http://localhost:8080 (use --auth with --password-file outside local development)
Quick Start
See the Quick Start Guide for complete examples with PostgreSQL and MySQL.
Documentation
- Quick Start Guide - Get started with PostgreSQL and MySQL
- TestQueue Framework - In-memory testing with MockClock for unit tests and time control
- Web Dashboard - Real-time web interface for queue monitoring and job management
- Job Tracing & Correlation - Distributed tracing, correlation IDs, and OpenTelemetry integration
- Job Dependencies & Workflows - Complex pipelines, job dependencies, and orchestration
- Dynamic Job Spawning - Fan-out processing, parent-child relationships, and spawn tree visualization
- Job Archiving & Retention - Policy-driven archival, compression, and compliance management
- Job Types & Configuration - Job creation, priorities, timeouts, cron jobs
- Worker Configuration - Worker setup, rate limiting, statistics
- Cron Scheduling - Recurring jobs with timezone support
- Priority System - Five-level priority system with weighted scheduling
- Batch Operations - High-performance bulk job processing
- Database Migrations - Progressive schema updates and database setup
- Job Encryption & PII Protection - Enterprise encryption, key management, and data protection
- Monitoring & Alerting - Prometheus metrics and notification systems
- Webhooks - Event delivery to HTTP endpoints, payload templates, HMAC signatures
- Event Streaming - Kafka, Kinesis and Pub/Sub delivery, retries and statistics
Basic Example
use ;
use json;
use ;
async
Workflow Example
Create complex data processing pipelines with job dependencies:
use ;
use json;
# async
Jobs will only execute when their dependencies are satisfied, enabling sophisticated data processing pipelines and business workflows.
Tracing Example
Enable comprehensive distributed tracing with OpenTelemetry integration:
use ;
use json;
use Arc;
async
This enables end-to-end tracing across your entire job processing pipeline with automatic span creation, correlation tracking, and integration with observability platforms like Jaeger, Zipkin, or DataDog.
Testing Example
Test your job processing logic with the in-memory TestQueue framework:
use ;
use ;
use json;
use Duration;
async
#
The TestQueue provides complete compatibility with the DatabaseQueue trait while offering deterministic time control through MockClock, making it perfect for testing complex workflows, retry logic, and time-dependent job processing.
Job Archiving Example
Configure automatic job archival for compliance and database performance:
use ;
use ;
# async
Archival moves completed/failed jobs to a separate table with compressed payloads, reducing the main table size while maintaining compliance requirements.
Job Encryption Example
Encrypt sensitive job payloads at rest. The queue encrypts jobs that ask for it when they are enqueued and the worker decrypts them just before calling the handler:
use ;
use json;
use ;
async
What you get:
- Encryption at rest: the
payloadcolumn holds{"encrypted": true}(whole payload) or the payload with thepii_fieldsreplaced by"[ENCRYPTED]"; the AES-256-GCM or ChaCha20-Poly1305 ciphertext, nonce and tag are stored in separate columns. PostgreSQL and MySQL. - Fail closed: enqueueing a job with an encryption config on a queue without an engine is an error; a worker that cannot decrypt a job (no engine, unknown key, tampered data) fails it without running the handler.
- Decryption only for the handler:
dequeue,get_job, the web dashboard and the CLI show the stored, redacted payload. CallJobQueue::decrypt_jobto read the plaintext. - Retention:
DatabaseQueue::purge_expired_encrypted_jobsdeletes finished encrypted jobs past their retention time. Archiving and restoring move the ciphertext without decrypting it. - Key management: decrypt-only keys for rotated key ids (
EncryptionEngine::with_decryption_key), KMS-wrapped data keys (AWS, GCP) that every process picks up after a rotation, Vault and Azure Key Vault sources (keys of exactly 32 bytes), and theKeyManagerfor stored keys and audit trails. Key material is wiped from memory when dropped. - CLI and dashboard:
cargo hammerworkandhammerwork-webread the application's[encryption]settings, encrypt the jobs they create like the application, and never write a plaintext job to a queue that holds encrypted jobs.cargo hammerwork backup create/restorekeep encrypted payloads (and every other column) intact.
See Job Encryption & PII Protection for details.
Web Dashboard
Start the real-time web dashboard for monitoring and managing your job queues:
# Start with PostgreSQL, without authentication (local development only)
# Start with authentication
# Start with custom configuration
The dashboard provides:
- Real-time Monitoring: Live queue statistics, job counts, and throughput metrics
- Job Management: View, retry, cancel, and inspect jobs with detailed payload information
- Queue Administration: Clear queues, monitor performance, and manage priorities
- Interactive Charts: Throughput graphs and job status distributions
- WebSocket Updates: Real-time updates without page refresh
- REST API: Complete programmatic access to all dashboard features
- Authentication: Secure access with bcrypt password hashing and rate limiting
Access the dashboard at http://localhost:8080 after starting the server.
Database Setup
Using Migrations (Recommended)
Hammerwork provides a migration system for progressive schema updates:
# Build the migration tool
# Run migrations
# Check migration status
# Start the web dashboard after migrations
Application Usage
Once migrations are run, your application can use the queue directly:
# use ;
# use json;
# use Arc;
# async
Database Schema
Hammerwork uses optimized tables with comprehensive indexing:
hammerwork_jobs- Main job table with priorities, timeouts, cron scheduling, retry strategies, result storage, distributed tracing, and encryption fieldshammerwork_jobs_archive- Archive table for completed/failed jobs with compressed payloads (v1.3.0+)hammerwork_encryption_keys- Encrypted key storage with master key encryption and audit trails (v1.7.0+)hammerwork_batches- Batch metadata and tracking (v0.7.0+)hammerwork_job_results- Job result storage with TTL and expiration (v0.8.0+)hammerwork_migrations- Migration tracking for schema evolution
The schema supports all features including job prioritization, advanced retry strategies, timeouts, cron scheduling, batch processing, result storage with TTL, distributed tracing with trace/correlation IDs, worker autoscaling, job archival with compression, job encryption with PII protection, enterprise key management, and comprehensive lifecycle tracking. See Database Migrations for details.
Development
Comprehensive testing with Docker containers:
# Start databases and run all tests
# Run specific database tests
See docs/integration-testing.md for complete development setup.
Examples
Working examples in examples/:
postgres_example.rs- PostgreSQL with timeouts and statisticsmysql_example.rs- MySQL with workers and prioritiescron_example.rs- Cron scheduling with timezonespriority_example.rs- Priority system demonstrationbatch_example.rs- Bulk job enqueuing and processingworker_batch_example.rs- Worker batch processing featuresretry_strategies.rs- Advanced retry patterns with exponential backoff and jitterresult_storage_example.rs- Job result storage and retrievalautoscaling_example.rs- Dynamic worker pool scaling based on queue depthtracing_example.rs- Distributed tracing with OpenTelemetry and event hooksencryption_example.rs- Job encryption, PII protection, and key managementaws_kms_encryption_example.rs- AWS KMS integration for enterprise key managementgcp_kms_encryption_example.rs- Google Cloud KMS integration for enterprise key managementvault_kms_encryption_example.rs- HashiCorp Vault KMS integration for enterprise key managementkey_management_example.rs- Enterprise key lifecycle and audit trails
Contributing
- Fork the repository and create a feature branch
- Run tests:
make integration-all - Ensure code follows Rust standards (
cargo fmt,cargo clippy) - Submit a pull request with tests and documentation
License
This project is licensed under the MIT License - see the LICENSE-MIT file for details.