Skip to content

Commit be1043c

Browse files
CodingAnarchyclaude
andcommitted
Add comprehensive cron job scheduling functionality
- Implement CronSchedule with timezone-aware scheduling using chrono-tz - Add cron expression parsing, validation, and preset schedules - Extend Job struct with cron fields: cron_schedule, next_run_at, recurring, timezone - Add builder methods: with_cron(), with_cron_schedule(), as_recurring() - Update database schema with cron columns and optimized indexes - Implement cron management API: enqueue_cron_job(), get_due_cron_jobs(), etc. - Add automatic job rescheduling after completion for recurring jobs - Include comprehensive test suite and cron_example.rs demonstration - Fix SQLx tuple limitations by using FromRow structs instead of tuples - Update version to 0.3.0 with full backward compatibility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 4d54651 commit be1043c

File tree

9 files changed

+1461
-109
lines changed

9 files changed

+1461
-109
lines changed

CHANGELOG.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,68 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.3.0] - 2025-06-26
9+
10+
### Added
11+
- **🕐 Comprehensive Cron Job Scheduling**
12+
- Full cron expression support with 6-field format (seconds, minutes, hours, day, month, weekday)
13+
- `CronSchedule` struct with timezone-aware scheduling using `chrono-tz`
14+
- Built-in presets for common schedules: `every_minute()`, `every_hour()`, `daily_at_midnight()`, `weekdays_at_9am()`, `mondays_at_noon()`
15+
- Cron expression validation and error handling with detailed error messages
16+
- Support for all standard timezones for global scheduling requirements
17+
18+
- **📋 Enhanced Job Structure for Recurring Jobs**
19+
- New fields: `cron_schedule`, `next_run_at`, `recurring`, `timezone`
20+
- Builder methods: `with_cron()`, `with_cron_schedule()`, `as_recurring()`, `with_timezone()`
21+
- Utility methods: `is_recurring()`, `has_cron_schedule()`, `calculate_next_run()`, `prepare_for_next_run()`
22+
- Smart next execution calculation based on cron expressions and timezones
23+
- Seamless integration with existing job timeout and retry mechanisms
24+
25+
- **🗄️ Database Schema Enhancements**
26+
- Added `cron_schedule`, `next_run_at`, `recurring`, `timezone` columns to both PostgreSQL and MySQL
27+
- Optimized indexes for recurring job queries: `idx_recurring_next_run`, `idx_cron_schedule`
28+
- Backward compatibility maintained with existing job records
29+
- Enhanced database queries to handle cron-specific fields efficiently
30+
31+
- **🔄 Intelligent Worker Integration**
32+
- Automatic rescheduling of completed recurring jobs based on cron expressions
33+
- Smart next-run calculation preserving timezone information
34+
- Integration with existing statistics and monitoring systems
35+
- Graceful handling of cron calculation errors with fallback to job completion
36+
- No impact on existing one-time job processing performance
37+
38+
- **📊 Comprehensive Management API**
39+
- `enqueue_cron_job()` - Create and schedule recurring jobs
40+
- `get_due_cron_jobs()` - Retrieve jobs ready for execution with optional queue filtering
41+
- `get_recurring_jobs()` - List all recurring jobs for a specific queue
42+
- `reschedule_cron_job()` - Manual rescheduling with automatic job state reset
43+
- `disable_recurring_job()` / `enable_recurring_job()` - Job lifecycle management
44+
- Full support in both PostgreSQL and MySQL implementations
45+
46+
- **🧪 Comprehensive Testing Suite**
47+
- 10 new cron-specific unit tests covering all functionality
48+
- 9 additional job integration tests for cron features
49+
- Timezone handling and edge case testing
50+
- Cron expression validation and serialization testing
51+
- Complete test coverage for recurring job lifecycle management
52+
53+
- **📖 Documentation and Examples**
54+
- Complete `cron_example.rs` demonstrating all cron functionality
55+
- Examples of daily, weekly, monthly, and custom interval scheduling
56+
- Timezone-aware scheduling examples (America/New_York)
57+
- Cron job management and lifecycle examples
58+
- Performance and monitoring integration examples
59+
60+
### Technical Implementation
61+
- **Dependencies**: Added `cron` (0.12) and `chrono-tz` (0.8) for robust scheduling
62+
- **Performance**: Optimized database queries with specialized indexes for recurring jobs
63+
- **Memory**: Efficient cron schedule caching with lazy initialization
64+
- **Error Handling**: Comprehensive error types for cron validation and timezone handling
65+
- **Compatibility**: Full backward compatibility with existing jobs and database schemas
66+
67+
### Breaking Changes
68+
- None - all changes are backward compatible with existing deployments
69+
870
## [0.2.2] - 2025-06-26
971

1072
### Added

Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ hammerwork = { path = "." }
1111
tokio = { version = "1.0", features = ["full"] }
1212
sqlx = { version = "0.8", features = ["runtime-tokio-rustls", "chrono", "uuid", "json"] }
1313
chrono = { version = "0.4", features = ["serde"] }
14+
chrono-tz = "0.8"
15+
cron = "0.12"
1416
uuid = { version = "1.0", features = ["v4", "serde"] }
1517
serde = { version = "1.0", features = ["derive"] }
1618
serde_json = "1.0"
@@ -22,9 +24,9 @@ tokio-test = "0.4"
2224

2325
[package]
2426
name = "hammerwork"
25-
version = "0.2.2"
27+
version = "0.3.0"
2628
edition = "2021"
27-
description = "A high-performance, database-driven job queue for Rust with PostgreSQL and MySQL support, featuring job timeouts, dead job management, and comprehensive statistics collection"
29+
description = "A high-performance, database-driven job queue for Rust with PostgreSQL and MySQL support, featuring cron scheduling, job timeouts, dead job management, and comprehensive statistics collection"
2830
license = "MIT"
2931
repository = "https://github.com/CodingAnarchy/hammerwork"
3032
authors = ["CodingAnarchy <[email protected]>"]
@@ -38,6 +40,8 @@ categories = ["database", "asynchronous", "concurrency"]
3840
tokio = { workspace = true }
3941
sqlx = { workspace = true }
4042
chrono = { workspace = true }
43+
chrono-tz = { workspace = true }
44+
cron = { workspace = true }
4145
uuid = { workspace = true }
4246
serde = { workspace = true }
4347
serde_json = { workspace = true }

0 commit comments

Comments
 (0)