Skip to content

Commit eb4d256

Browse files
CodingAnarchyclaude
andcommitted
fix: Resolve compilation issues and add comprehensive TestQueue documentation
## Examples Compilation Fixes - Add missing example configurations in Cargo.toml with proper feature requirements - Fix database pool setup with conditional compilation in autoscaling_example.rs - Replace generic function signatures with concrete types using type aliases in retry_strategies.rs - Fix job priority methods (.with_priority() instead of .as_high()) - Fix batch creation using .with_jobs() builder pattern - Fix workflow creation using .add_job() chain and .depends_on() for dependencies - Fix cron expressions to use 6-field format (including seconds) - Fix field access for QueueStats (use .statistics.completed instead of .completed) - Remove Worker usage from TestQueue example with proper documentation of incompatibility ## TestQueue Documentation & Testing - Add comprehensive docs/testing.md with complete TestQueue usage guide - Document TestQueue limitations: designed for testing job logic, not Worker functionality - Add extensive examples for delayed jobs, cron jobs, priorities, batches, workflows - Fix test_cron_job test failure by advancing MockClock before dequeuing cron jobs - Add TestQueue feature to README with examples and documentation links ## Key Features Added - Complete TestQueue documentation with 400+ lines of usage examples - Clear separation of concerns: TestQueue for job logic, real databases for Worker testing - Best practices guide for effective TestQueue usage in unit tests - All 187 unit tests, 150 doctests, and integration tests now passing 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 308389c commit eb4d256

File tree

7 files changed

+1414
-133
lines changed

7 files changed

+1414
-133
lines changed

Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,27 @@ required-features = ["postgres"]
112112
name = "priority_example"
113113
required-features = ["postgres"]
114114

115+
[[example]]
116+
name = "batch_example"
117+
required-features = ["postgres"]
118+
119+
[[example]]
120+
name = "worker_batch_example"
121+
required-features = ["postgres"]
122+
123+
[[example]]
124+
name = "retry_strategies"
125+
required-features = ["postgres"]
126+
127+
[[example]]
128+
name = "result_storage_example"
129+
required-features = ["postgres"]
130+
131+
[[example]]
132+
name = "autoscaling_example"
133+
required-features = ["postgres"]
134+
135+
[[example]]
136+
name = "test_queue_example"
137+
required-features = ["test"]
138+

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ A high-performance, database-driven job queue for Rust with comprehensive featur
55
## Features
66

77
- **📊 Web Dashboard**: Modern real-time web interface for monitoring queues, managing jobs, and system administration with authentication and WebSocket updates
8+
- **🧪 TestQueue Framework**: Complete in-memory testing implementation with MockClock for deterministic testing of time-dependent features, workflows, and job processing
89
- **🔍 Job Tracing & Correlation**: Comprehensive distributed tracing with OpenTelemetry integration, trace IDs, correlation IDs, and lifecycle event hooks
910
- **🔗 Job Dependencies & Workflows**: Create complex data processing pipelines with job dependencies, sequential chains, and parallel processing with synchronization barriers
1011
- **Multi-database support**: PostgreSQL and MySQL backends with optimized dependency queries
@@ -39,7 +40,7 @@ hammerwork = { version = "1.2", features = ["postgres", "tracing"] }
3940
hammerwork = { version = "1.2", features = ["postgres"], default-features = false }
4041
```
4142

42-
**Feature Flags**: `postgres`, `mysql`, `metrics` (default), `alerting` (default), `tracing` (optional)
43+
**Feature Flags**: `postgres`, `mysql`, `metrics` (default), `alerting` (default), `tracing` (optional), `test` (for TestQueue)
4344

4445
### Web Dashboard (Optional)
4546

@@ -66,6 +67,7 @@ See the [Quick Start Guide](docs/quick-start.md) for complete examples with Post
6667
## Documentation
6768
6869
- **[Quick Start Guide](docs/quick-start.md)** - Get started with PostgreSQL and MySQL
70+
- **[TestQueue Framework](docs/testing.md)** - In-memory testing with MockClock for unit tests and time control
6971
- **[Web Dashboard](hammerwork-web/README.md)** - Real-time web interface for queue monitoring and job management
7072
- **[Job Tracing & Correlation](docs/tracing.md)** - Distributed tracing, correlation IDs, and OpenTelemetry integration
7173
- **[Job Dependencies & Workflows](docs/workflows.md)** - Complex pipelines, job dependencies, and orchestration
@@ -230,6 +232,49 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
230232
231233
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.
232234
235+
## Testing Example
236+
237+
Test your job processing logic with the in-memory `TestQueue` framework:
238+
239+
```rust
240+
use hammerwork::queue::test::{TestQueue, MockClock};
241+
use hammerwork::{Job, JobStatus, queue::DatabaseQueue};
242+
use serde_json::json;
243+
use chrono::Duration;
244+
245+
#[tokio::test]
246+
async fn test_delayed_job_processing() {
247+
let clock = MockClock::new();
248+
let queue = TestQueue::with_clock(clock.clone());
249+
250+
// Schedule a job for 1 hour from now
251+
let future_time = clock.now() + Duration::hours(1);
252+
let job = Job::new("test_queue".to_string(), json!({"task": "delayed_task"}))
253+
.with_scheduled_at(future_time);
254+
255+
let job_id = queue.enqueue(job).await.unwrap();
256+
257+
// Job shouldn't be available immediately
258+
assert!(queue.dequeue("test_queue").await.unwrap().is_none());
259+
260+
// Advance time past scheduled time
261+
clock.advance(Duration::hours(2));
262+
263+
// Now job should be available for processing
264+
let dequeued = queue.dequeue("test_queue").await.unwrap().unwrap();
265+
assert_eq!(dequeued.id, job_id);
266+
267+
// Complete the job
268+
queue.complete_job(job_id).await.unwrap();
269+
270+
// Verify completion
271+
let completed = queue.get_job(job_id).await.unwrap().unwrap();
272+
assert_eq!(completed.status, JobStatus::Completed);
273+
}
274+
```
275+
276+
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.
277+
233278
## Web Dashboard
234279
235280
Start the real-time web dashboard for monitoring and managing your job queues:

0 commit comments

Comments
 (0)