Hammerwork
A high-performance, database-driven job queue for Rust with support for both PostgreSQL and MySQL.
Features
- Multi-database support: Works with both PostgreSQL and MySQL
- Async/await: Built on Tokio for high concurrency
- Reliable: Uses database transactions for job processing
- Retries: Configurable retry logic with exponential backoff
- Delayed jobs: Schedule jobs to run at specific times
- Worker pools: Multiple workers can process jobs concurrently
- Type-safe: Leverages Rust's type system for safety
Installation
Add this to your Cargo.toml:
[]
= "0.1"
# Choose your database
= { = "0.1", = ["postgres"] }
# or
= { = "0.1", = ["mysql"] }
Quick Start
PostgreSQL Example
use ;
use json;
use PgPool;
use Arc;
async
MySQL Example
use ;
use json;
use MySqlPool;
use Arc;
async
Job Types
Basic Job
use Job;
use json;
let job = new;
Delayed Job
use Duration;
let delayed_job = with_delay;
Job with Custom Retry Logic
let job = new
.with_max_attempts;
Worker Configuration
let worker = new
.with_poll_interval // How often to check for jobs
.with_max_retries // Max retry attempts
.with_retry_delay; // Delay between retries
Database Schema
Hammerwork creates a single table hammerwork_jobs with the following structure:
id: Unique job identifier (UUID)queue_name: Name of the queuepayload: JSON payload datastatus: Current job status (pending, running, completed, failed, retrying)attempts: Number of processing attemptsmax_attempts: Maximum allowed attemptscreated_at: When the job was createdscheduled_at: When the job should be processedstarted_at: When processing begancompleted_at: When processing finishederror_message: Error details if job failed
Development & Testing
Local Development Setup
Hammerwork includes comprehensive integration testing with Docker containers:
# Clone the repository
# Start database containers and run all tests
# Or run specific database tests
# Run unit tests only
# Performance benchmarks
Prerequisites
- Docker & Docker Compose: For database containers
- Rust 1.75+: For building and running tests
- Make (optional): For convenient commands
Available Commands
# Database management
# Testing
# Development
# Cleanup
Integration Testing
The project includes comprehensive integration tests that validate:
- ✅ Job queue functionality with real databases
- ✅ PostgreSQL and MySQL compatibility
- ✅ Worker pool management and job processing
- ✅ Performance benchmarks and regression testing
- ✅ Containerized deployment scenarios
- ✅ End-to-end job lifecycle management
See docs/integration-testing.md for detailed testing documentation.
CI/CD Pipeline
GitHub Actions automatically runs:
- Unit Tests: Fast validation without dependencies
- PostgreSQL Integration: Full database testing with PostgreSQL 16
- MySQL Integration: Full database testing with MySQL 8.0
- Docker Tests: Containerized deployment validation
- Security Audit: Vulnerability scanning
- Performance Tests: Benchmark regression detection (scheduled daily)
Examples
Complete working examples are available in the examples/ directory:
postgres_example.rs: PostgreSQL job processingmysql_example.rs: MySQL job processing with multiple workers
Run examples with:
# PostgreSQL example (requires running PostgreSQL)
# MySQL example (requires running MySQL)
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Run tests:
make integration-all - Make your changes with appropriate tests
- Ensure all tests pass:
make ci - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Create a Pull Request
Please ensure your code:
- ✅ Includes appropriate tests
- ✅ Follows Rust formatting (
cargo fmt) - ✅ Passes all linting (
cargo clippy) - ✅ Maintains or improves test coverage
- ✅ Includes documentation for new features
License
This project is licensed under the MIT License - see the LICENSE-MIT file for details.