cargo-hammerwork
A comprehensive cargo subcommand for managing Hammerwork job queues with advanced tooling and monitoring capabilities.
Installation
Install from the workspace:
# Build and install locally
# Or build for development
Overview
cargo-hammerwork provides a modern, modular CLI for managing Hammerwork-based applications with support for:
- 🗄️ Database Migration Management - Setup and maintain database schemas
- ⚙️ Configuration Management - Centralized config with file and environment support
- 🧩 Modular Architecture - Clean separation of concerns with dedicated command modules
- 🐘 Multi-Database Support - PostgreSQL and MySQL compatibility
- 📊 Advanced Monitoring - Real-time dashboards and health checks
- 👷 Worker Management - Control job processing workers and pools
- 🎯 Queue Operations - Comprehensive queue management and statistics
- 📋 Job Management - Full job lifecycle control and management
- 📦 Batch Operations - Bulk job processing and management
- ⏰ Cron Management - Recurring job scheduling and management
- 🔧 Database Maintenance - Cleanup, optimization, and health checks
- 🔄 Workflow Management - Job dependencies and complex pipelines
- 💾 Backup & Restore - Database backup and recovery operations
Quick Start
1. Database Setup
# Run migrations to set up the database schema
# Check migration status
2. Configuration
# Set your default database URL
# View current configuration
# Set other defaults
Command Structure
The CLI is organized into logical command groups:
Migration Commands
# Database migration operations
Configuration Commands
# Configuration management
Job Management Commands
# Job lifecycle management
Worker Management Commands
# Worker control and monitoring
Queue Management Commands
# Queue operations and statistics
Monitoring Commands
# Real-time monitoring and health checks
Batch Operation Commands
# Bulk job operations
Cron Management Commands
# Recurring job scheduling
Maintenance Commands
# Database maintenance and optimization
Workflow Commands
# Job dependencies and complex pipelines
Backup Commands
# Database backup and recovery
Architecture & Design
Modular Structure
cargo-hammerwork/
├── src/
│ ├── commands/ # Command implementations
│ │ ├── migration.rs # Database migration operations
│ │ ├── config.rs # Configuration management
│ │ ├── job.rs # Job management (framework)
│ │ ├── queue.rs # Queue operations (framework)
│ │ ├── worker.rs # Worker control (framework)
│ │ └── monitor.rs # Monitoring & observability (framework)
│ ├── config/ # Configuration system
│ │ └── mod.rs # Config loading and management
│ ├── utils/ # Shared utilities
│ │ ├── database.rs # Database connection handling
│ │ ├── display.rs # Table formatting and display
│ │ └── validation.rs # Input validation
│ └── main.rs # CLI entry point
Command Feature Highlights
Job Management
- List jobs with advanced filtering (queue, status, priority, time-based)
- Job enqueueing with priority, delays, timeouts, and retry configuration
- Bulk operations (retry, cancel, purge) with safety confirmations
- Detailed job inspection with full lifecycle tracking
Queue Management
- Queue listing with comprehensive statistics
- Queue operations (clear, pause, resume)
- Health monitoring with configurable thresholds
- Detailed vs. summary statistics views
Worker Management
- Worker lifecycle control (start, stop, status)
- Configurable worker pools with priority handling
- Real-time worker monitoring and metrics
- Graceful shutdown and resource management
Monitoring & Observability
- Real-time dashboard with auto-refresh
- System health checks with JSON/table output
- Performance metrics with configurable time periods
- Log tailing and filtering capabilities
Advanced Features
- Batch Operations: Bulk job processing with progress tracking
- Cron Scheduling: Time-based recurring job management
- Database Maintenance: Cleanup, optimization, and health monitoring
- Workflow Management: Complex job dependency orchestration
- Backup & Restore: Complete database backup and recovery
Configuration System
Supports multiple configuration sources with proper precedence:
- Environment Variables (highest priority)
- Configuration File (
~/.config/hammerwork/config.toml) - Default Values (lowest priority)
Example configuration file:
= "postgres://localhost/hammerwork"
= "emails"
= 50
= "info"
= 5
Database Support
- PostgreSQL: Full support with optimized queries and indexes
- MySQL: Complete compatibility with database-specific optimizations
- Connection Pooling: Configurable pool sizes for optimal performance
- Migration Safety: Atomic operations with rollback capabilities
Advanced Usage
Environment Integration
# Set environment variables
# Commands will automatically use environment settings
Cargo Subcommand Usage
# Works as a standard cargo subcommand
# Or direct invocation
Global Options
# Enable verbose logging
# Suppress output (errors only)
Development & Extension
The modular architecture makes it easy to extend functionality:
- Add New Commands: Create modules in
src/commands/ - Extend Utilities: Add shared functionality in
src/utils/ - Database Support: Extend
DatabasePoolfor new database types - Configuration: Add new config keys in
Configstruct
Testing
# Run unit tests
# Set up test databases (requires Docker)
# Run integration tests with databases
# Check CLI structure
# Test specific commands
Test Database Management
The project includes convenient scripts for managing test databases:
# From the project root directory:
# Set up test databases
# Check database status
# Run integration tests
# Stop databases
# Remove databases
Test database connection strings:
- PostgreSQL:
postgres://postgres:hammerwork@localhost:5433/hammerwork - MySQL:
mysql://root:hammerwork@localhost:3307/hammerwork
Development Workflow
A development helper script is available for common tasks:
# From the project root directory:
# Run full check (format + lint + test)
# Run tests with database integration
# CLI development workflow
# Build everything
# Format code
# Run clippy
# Generate docs
# See all available commands
Code Quality
The codebase follows Rust best practices:
- Error Handling: Comprehensive error types with context
- Documentation: Inline docs and examples
- Modularity: Clean separation of concerns
- Type Safety: Leverages Rust's type system for reliability
- Async/Await: Modern async patterns throughout
Integration with Hammerwork
This CLI is designed to work seamlessly with Hammerwork applications:
- Database Schema: Creates and maintains compatible table structures
- Job Format: Handles Hammerwork job formats and priorities
- Worker Compatibility: Designed to work with Hammerwork workers
- Migration Safety: Respects existing Hammerwork installations
Troubleshooting
Common Issues
- Database Connection Errors: Verify your DATABASE_URL and database accessibility
- Permission Errors: Ensure database user has necessary privileges
- Configuration Issues: Check config file location with
config path
Debugging
# Enable debug logging
# Check configuration
# Verify database connectivity
Future Roadmap
Planned enhancements include:
- Web Dashboard: Browser-based monitoring interface
- Cluster Management: Multi-node coordination features
- Plugin System: Extensible plugin architecture
- Advanced Analytics: Historical performance analysis and trending
- External Integrations: Webhook notifications and third-party service integration
License
Same as the parent Hammerwork project: MIT OR Apache-2.0