Skip to content

Commit b58a8de

Browse files
CodingAnarchyclaude
andcommitted
feat: Complete cargo-hammerwork CLI with full database compatibility
This release introduces a comprehensive CLI tool for managing Hammerwork job queues with complete PostgreSQL and MySQL support. ## New Features - 🛠️ Complete CLI tool with 10+ command groups - 🗄️ Full PostgreSQL and MySQL database support - 📊 Real-time monitoring and metrics - 🔄 Backup and restore operations - ⏰ Cron job scheduling - 🔨 Database maintenance tools - 📦 Batch job processing - 👷 Worker management ## Command Groups - migration: Database schema management - job: Job lifecycle operations (enqueue, list, get, retry, cancel) - queue: Queue management and statistics - worker: Worker pool management - monitor: Real-time monitoring and health checks - backup: Data backup and restore - batch: Bulk job operations - cron: Scheduled job management - maintenance: Database optimization and integrity - config: Configuration management ## Technical Improvements - ✅ Fixed all database type compatibility issues - ✅ Resolved all clippy linting warnings - ✅ MySQL syntax fixes for date intervals - ✅ Database-agnostic helper functions - ✅ Comprehensive test suite - ✅ Docker-based test infrastructure - ✅ Developer tooling and scripts ## Database Compatibility - Both PostgreSQL and MySQL fully supported - Identical functionality across both databases - Database-specific optimizations where appropriate - Seamless switching between database types ## Testing - 19 passing unit tests - Integration tests for both databases - Manual CLI validation completed - Comprehensive error handling 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent c682b27 commit b58a8de

34 files changed

+6575
-236
lines changed

CLAUDE.md

Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,36 @@ cargo test
3131
cargo test --features postgres
3232
cargo test --features mysql
3333

34+
# Test CLI crate specifically
35+
cargo test -p cargo-hammerwork
36+
3437
# Run examples
3538
cargo run --example postgres_example --features postgres
3639
cargo run --example mysql_example --features mysql
3740
cargo run --example cron_example --features postgres
3841
cargo run --example priority_example --features postgres
3942

43+
# Test CLI functionality
44+
cargo run -p cargo-hammerwork -- --help
45+
cargo run -p cargo-hammerwork -- migration --help
46+
cargo run -p cargo-hammerwork -- config --help
47+
4048
# Check code formatting
4149
cargo fmt --check
4250

4351
# Run clippy for linting
4452
cargo clippy -- -D warnings
53+
54+
# Set up test databases for integration testing
55+
./scripts/setup-test-databases.sh both
56+
57+
# Run integration tests with databases
58+
./scripts/setup-test-databases.sh test
59+
60+
# Development helper shortcuts
61+
./scripts/dev.sh check # Run format + lint + test
62+
./scripts/dev.sh test-db # Run all tests including database integration
63+
./scripts/dev.sh cli # CLI development workflow
4564
```
4665

4766
### Feature Flags
@@ -121,10 +140,16 @@ cargo clippy --all-features -- -D warnings
121140
# 3. Run complete test suite with all features
122141
cargo test --all-features
123142

124-
# 4. Verify examples compile and work
143+
# 4. Test CLI crate specifically
144+
cargo test -p cargo-hammerwork
145+
146+
# 5. Verify examples compile and work
125147
cargo check --examples --all-features
126148

127-
# 5. Build release version to catch optimization issues
149+
# 6. Test CLI functionality
150+
cargo check -p cargo-hammerwork
151+
152+
# 7. Build release version to catch optimization issues
128153
cargo build --release --all-features
129154
```
130155

@@ -147,6 +172,8 @@ cargo build --release --all-features
147172
- Test with both PostgreSQL and MySQL features
148173
- Cover edge cases and error conditions
149174
- Use `#[ignore]` for tests requiring database connections
175+
- **CLI Testing**: Ensure cargo-hammerwork crate has comprehensive tests for all command modules
176+
- **Test Organization**: Place unit tests in the same file as the code being tested using `#[cfg(test)]` modules at the bottom of each file. Only use separate test files for integration tests that span multiple modules.
150177

151178
4. **Error Handling**
152179
- Use `thiserror` for structured error types
@@ -185,6 +212,39 @@ cargo build --release --all-features
185212
- Push to origin: `git push origin main && git push origin --tags`
186213
- Publish to crates.io: `cargo publish`
187214

215+
### Test Database Setup
216+
217+
The project includes scripts to easily set up PostgreSQL and MySQL test databases using Docker:
218+
219+
```bash
220+
# Set up both PostgreSQL and MySQL test databases
221+
./scripts/setup-test-databases.sh both
222+
223+
# Set up only PostgreSQL
224+
./scripts/setup-test-databases.sh postgres
225+
226+
# Set up only MySQL
227+
./scripts/setup-test-databases.sh mysql
228+
229+
# Check status of test databases
230+
./scripts/setup-test-databases.sh status
231+
232+
# Run integration tests
233+
./scripts/setup-test-databases.sh test
234+
235+
# Stop test databases
236+
./scripts/setup-test-databases.sh stop
237+
238+
# Remove test databases
239+
./scripts/setup-test-databases.sh remove
240+
```
241+
242+
Database connection details:
243+
- **PostgreSQL**: `postgres://postgres:hammerwork@localhost:5433/hammerwork`
244+
- **MySQL**: `mysql://root:hammerwork@localhost:3307/hammerwork`
245+
246+
The CLI migrations are automatically run when setting up the databases.
247+
188248
### Database Development Guidelines
189249

190250
1. **Schema Changes**
@@ -204,6 +264,50 @@ cargo build --release --all-features
204264
- Handle database-specific limitations gracefully
205265
- Test all features with both databases
206266

267+
## CLI Development Guidelines
268+
269+
### SQL Query Strategy
270+
271+
The `cargo-hammerwork` crate uses **dynamic SQL queries** with `sqlx::query()` rather than compile-time `sqlx::query!()` macros to support:
272+
- Complex filtering with optional parameters
273+
- Database-agnostic queries (PostgreSQL and MySQL)
274+
- Runtime query building for CLI flexibility
275+
276+
**Security**: All queries use parameterized statements to prevent SQL injection. Comprehensive tests in `tests/sql_query_tests.rs` validate query correctness.
277+
278+
### Feature Integration with CLI Tooling
279+
280+
**IMPORTANT**: When adding new features to the core Hammerwork library, ALWAYS consider and implement corresponding CLI tooling in the `cargo-hammerwork` crate:
281+
282+
1. **New Core Features**
283+
- Add appropriate CLI commands in `cargo-hammerwork/src/commands/`
284+
- Expose new functionality through the CLI interface
285+
- Update CLI help text and documentation
286+
- Add CLI tests for the new functionality
287+
288+
2. **CLI Command Categories**
289+
- **Migration**: Database schema management
290+
- **Job**: Job lifecycle management (enqueue, list, retry, cancel, inspect)
291+
- **Queue**: Queue operations (list, clear, pause, resume, stats)
292+
- **Worker**: Worker control (start, stop, status, pool management)
293+
- **Monitor**: Real-time monitoring and health checks
294+
- **Config**: Configuration management
295+
296+
3. **CLI Testing Requirements**
297+
- **Unit tests for command modules**: Each command module must have inline `#[cfg(test)]` modules
298+
- **SQL Query Validation**: Comprehensive tests in `tests/sql_query_tests.rs` validate all dynamic SQL queries
299+
- **Integration tests**: Database-backed tests with `#[ignore]` attribute for optional execution
300+
- **CLI argument parsing tests**: Validate clap command structure and argument validation
301+
- **Configuration loading tests**: Test config file loading, environment variable precedence
302+
- **Error handling tests**: Include SQL injection prevention and input validation tests
303+
- **Query Security**: All queries use parameterized statements (`sqlx::query(...).bind(...)`) to prevent SQL injection
304+
305+
4. **CLI Documentation**
306+
- Update CLI README when adding commands
307+
- Include usage examples in help text
308+
- Document configuration options
309+
- Maintain command reference documentation
310+
207311
### Git Workflow
208312

209313
1. **Commit Messages**
@@ -220,4 +324,5 @@ cargo build --release --all-features
220324
3. **Code Reviews**
221325
- Review for correctness, performance, and maintainability
222326
- Ensure tests pass on all supported platforms
223-
- Verify documentation is updated
327+
- Verify documentation is updated
328+
- **CLI Review**: Verify that new core features have appropriate CLI tooling

Cargo.toml

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
[workspace]
22
members = [
33
".",
4+
"cargo-hammerwork",
45
"integrations/postgres-integration",
56
"integrations/mysql-integration",
67
]
78
resolver = "2"
89

10+
[workspace.package]
11+
version = "1.0.0"
12+
edition = "2024"
13+
license = "MIT"
14+
repository = "https://github.com/CodingAnarchy/hammerwork"
15+
authors = ["CodingAnarchy <[email protected]>"]
16+
homepage = "https://github.com/CodingAnarchy/hammerwork"
17+
documentation = "https://docs.rs/hammerwork"
18+
rust-version = "1.86"
19+
920
[workspace.dependencies]
1021
hammerwork = { path = "." }
1122
tokio = { version = "1.0", features = ["full"] }
@@ -26,21 +37,27 @@ prometheus = { version = "0.13" }
2637
reqwest = { version = "0.12", features = ["json"] }
2738
warp = { version = "0.3" }
2839
clap = { version = "4.0", features = ["derive"] }
40+
anyhow = "1.0"
41+
comfy-table = "7.0"
42+
indicatif = "0.17"
43+
toml = "0.8"
44+
dirs = "5.0"
45+
tempfile = "3.8"
2946

3047
[package]
3148
name = "hammerwork"
32-
version = "1.0.0"
33-
edition = "2024"
3449
description = "A high-performance, database-driven job queue for Rust with PostgreSQL and MySQL support, featuring job prioritization, cron scheduling, timeouts, rate limiting, Prometheus metrics, alerting, and comprehensive statistics collection"
35-
license = "MIT"
36-
repository = "https://github.com/CodingAnarchy/hammerwork"
37-
authors = ["CodingAnarchy <[email protected]>"]
38-
homepage = "https://github.com/CodingAnarchy/hammerwork"
39-
documentation = "https://docs.rs/hammerwork"
4050
readme = "README.md"
4151
keywords = ["database", "job-queue", "async", "postgres", "mysql"]
4252
categories = ["database", "asynchronous", "concurrency"]
43-
rust-version = "1.86"
53+
version.workspace = true
54+
edition.workspace = true
55+
license.workspace = true
56+
repository.workspace = true
57+
authors.workspace = true
58+
homepage.workspace = true
59+
documentation.workspace = true
60+
rust-version.workspace = true
4461

4562
[dependencies]
4663
tokio = { workspace = true }
@@ -88,6 +105,3 @@ required-features = ["postgres"]
88105
name = "priority_example"
89106
required-features = ["postgres"]
90107

91-
[[bin]]
92-
name = "cargo-hammerwork"
93-
path = "src/bin/cargo-hammerwork.rs"

cargo-hammerwork/Cargo.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[package]
2+
name = "cargo-hammerwork"
3+
description = "A comprehensive cargo subcommand for managing Hammerwork job queues with advanced tooling and monitoring capabilities"
4+
keywords = ["cargo", "cli", "hammerwork", "job-queue", "database"]
5+
categories = ["command-line-utilities", "development-tools::cargo-plugins"]
6+
version.workspace = true
7+
edition.workspace = true
8+
license.workspace = true
9+
repository.workspace = true
10+
authors.workspace = true
11+
homepage.workspace = true
12+
documentation.workspace = true
13+
rust-version.workspace = true
14+
15+
[[bin]]
16+
name = "cargo-hammerwork"
17+
path = "src/main.rs"
18+
19+
[dependencies]
20+
hammerwork = { workspace = true, features = ["postgres", "mysql"] }
21+
clap = { workspace = true, features = ["env"] }
22+
tokio = { workspace = true }
23+
anyhow = { workspace = true }
24+
tracing = { workspace = true }
25+
tracing-subscriber = { workspace = true }
26+
sqlx = { workspace = true, features = ["postgres", "mysql"] }
27+
serde = { workspace = true }
28+
serde_json = { workspace = true }
29+
chrono = { workspace = true }
30+
uuid = { workspace = true }
31+
comfy-table = { workspace = true }
32+
indicatif = { workspace = true }
33+
toml = { workspace = true }
34+
dirs = { workspace = true }
35+
cron = { workspace = true }
36+
37+
[dev-dependencies]
38+
tempfile = "3.8"
39+
tokio-test = { workspace = true }

0 commit comments

Comments
 (0)