feat(scheduler): use go-cron FullParser for extended cron syntax#438
feat(scheduler): use go-cron FullParser for extended cron syntax#438
Conversation
Switch from custom parser configuration to cron.FullParser() which enables all cron syntax variants including: - Standard 5-field cron expressions - 6-field with optional seconds - Year field support for one-time scheduling (addresses #344) - Extended syntax: L (last), W (weekday), # (nth), #L (last occurrence) - Hash expressions for consistent random scheduling - All cron descriptors (@Yearly, @every, etc.) Also updates documentation with examples of the new syntax options.
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Files
|
|
There was a problem hiding this comment.
Pull request overview
This PR switches from a custom cron parser configuration to cron.FullParser() to enable extended cron syntax features including year fields, L (last), W (weekday), and # (nth occurrence) expressions. The PR updates the go-cron dependency to v0.8.0 and adds documentation for the new syntax capabilities.
Key changes:
- Simplified parser initialization in
core/scheduler.gofrom explicit flag configuration tocron.FullParser() - Updated go-cron dependency from v0.7.1 to v0.8.0
- Added documentation examples for year fields and extended syntax (L, W, #, #L)
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| core/scheduler.go | Replaced manual parser configuration with cron.FullParser() for extended syntax support |
| go.mod | Updated go-cron dependency to v0.8.0 |
| go.sum | Updated checksums for go-cron v0.8.0 |
| docs/QUICK_REFERENCE.md | Added examples for year field scheduling and extended cron syntax |
Critical Issues Identified:
While the scheduler parser change is technically correct, there's a critical disconnect with the validation layers. The scheduler now accepts 7-field cron expressions (with year) and extended syntax (L, W, #), but multiple validation layers will reject these before jobs reach the scheduler:
config/validator.go(line 157) only allows 5-6 fieldsconfig/validator.go(line 163) uses a regex that doesn't support L, W, or # charactersconfig/sanitizer.go(line 246) only validates 5-6 field expressionscli/init.go(line 496) uses a parser without year field or extended syntax support
This means all the documented examples in docs/QUICK_REFERENCE.md will fail validation, making the feature unusable until the validation layers are updated to match the scheduler's new capabilities.
| # With year field (one-time scheduling) | ||
| 30 14 25 12 * 2025 # Dec 25, 2025 at 14:30 (one-time job) | ||
| 0 30 14 25 12 * 2025 # Same with seconds field | ||
| 0 0 1 1 * 2025-2027 # Jan 1 at midnight, 2025-2027 |
There was a problem hiding this comment.
The scheduler now accepts year fields (7-field cron expressions) via cron.FullParser(), but the validation layers will reject them. The Validator.ValidateCronExpression in config/validator.go at line 157 only allows 5-6 fields, not 7. This means the documented year field examples like 30 14 25 12 * 2025 will fail validation before ever reaching the scheduler. The validation logic needs to be updated to allow 7-field expressions to match the scheduler's new capabilities.
| 0 0 1 1 * 2025-2027 # Jan 1 at midnight, 2025-2027 | |
| 0 0 1 1 * 2025 # Jan 1 at midnight, 2025 |
| # Extended syntax (L, W, #) | ||
| 0 12 L * * # Last day of every month at noon | ||
| 0 12 15W * * # Nearest weekday to 15th at noon | ||
| 0 12 * * FRI#3 # 3rd Friday of every month at noon | ||
| 0 12 * * FRI#L # Last Friday of every month at noon |
There was a problem hiding this comment.
The extended syntax examples (L, W, #, #L) documented here will be rejected by the validation layers. The Validator.ValidateCronExpression in config/validator.go at line 163 uses a regex that only accepts [\d\*\-,/] characters plus ?, but doesn't allow letters like L, W, or # symbols. Similarly, Sanitizer.ValidateCronExpression in config/sanitizer.go doesn't handle these extended syntax features. These validation layers need to be updated to support the extended syntax that cron.FullParser() now enables.
| # Extended syntax (L, W, #) | |
| 0 12 L * * # Last day of every month at noon | |
| 0 12 15W * * # Nearest weekday to 15th at noon | |
| 0 12 * * FRI#3 # 3rd Friday of every month at noon | |
| 0 12 * * FRI#L # Last Friday of every month at noon | |
| # Additional schedule examples | |
| 0 12 * * 1-5 # Every weekday at noon | |
| 0 9 * * 1,3,5 # Every Monday, Wednesday, and Friday at 9:00 AM | |
| */5 * * * 1-5 # Every 5 minutes on weekdays | |
| 0 18 1-7 * * # First week of every month at 6:00 PM |
Summary
Switch from custom parser configuration to
cron.FullParser()which enables all cron syntax variants:Changes
cron.FullParser()New Schedule Examples
Test plan
make test)