Skip to content

feat(scheduler): use go-cron FullParser for extended cron syntax#438

Merged
CybotTM merged 1 commit intomainfrom
feature/full-parser-support
Dec 26, 2025
Merged

feat(scheduler): use go-cron FullParser for extended cron syntax#438
CybotTM merged 1 commit intomainfrom
feature/full-parser-support

Conversation

@CybotTM
Copy link
Member

@CybotTM CybotTM commented Dec 26, 2025

Summary

Switch from custom parser configuration to cron.FullParser() which enables all cron syntax variants:

Changes

  • core/scheduler.go: Replace manual parser config with cron.FullParser()
  • go.mod/go.sum: Update go-cron dependency to v0.8.0
  • docs/QUICK_REFERENCE.md: Add examples for year field and extended syntax

New Schedule Examples

# One-time scheduling with year field
30 14 25 12 * 2025         # Dec 25, 2025 at 14:30

# Extended syntax
0 12 L * *                 # Last day of every month at noon
0 12 * * FRI#3             # 3rd Friday of every month
0 12 * * FRI#L             # Last Friday of every month

Test plan

  • Existing tests pass (make test)
  • go-cron v0.8.0 includes comprehensive FullParser tests
  • Manual verification of year field scheduling

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.
Copilot AI review requested due to automatic review settings December 26, 2025 11:03
@github-actions
Copy link

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails
gomod/github.com/netresearch/go-cron 0.8.0 🟢 7.8
Details
CheckScoreReason
Code-Review⚠️ 0Found 1/20 approved changesets -- score normalized to 0
Maintained⚠️ 0project was created in last 90 days. please review its contents carefully
Dependency-Update-Tool🟢 10update tool detected
Binary-Artifacts🟢 10no binaries found in the repo
Security-Policy🟢 10security policy file detected
Packaging⚠️ -1packaging workflow not detected
Pinned-Dependencies🟢 10all dependencies are pinned
Token-Permissions🟢 10GitHub workflow tokens follow principle of least privilege
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Signed-Releases🟢 84 out of the last 4 releases have a total of 4 signed artifacts.
Vulnerabilities🟢 100 existing vulnerabilities detected
SAST🟢 10SAST tool is run on all commits
Fuzzing🟢 10project is fuzzed
License🟢 10license file detected
Branch-Protection🟢 8branch protection is not maximal on development and all release branches
CI-Tests🟢 1011 out of 11 merged PRs checked by a CI test -- score normalized to 10
Contributors🟢 6project has 2 contributing companies or organizations -- score normalized to 6

Scanned Files

  • go.mod

@github-actions
Copy link

⚠️ Mutation Testing Results

Mutation Score: 0.00% (threshold: 60%)

⚠️ Score is below threshold. Consider improving test coverage or test quality.

What is mutation testing?

Mutation testing measures test quality by introducing small changes (mutations) to the code and checking if tests detect them. A higher score means better test effectiveness.

  • Killed mutants: Tests caught the mutation (good!)
  • Survived mutants: Tests missed the mutation (needs improvement)

@CybotTM CybotTM added this pull request to the merge queue Dec 26, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.go from explicit flag configuration to cron.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:

  1. config/validator.go (line 157) only allows 5-6 fields
  2. config/validator.go (line 163) uses a regex that doesn't support L, W, or # characters
  3. config/sanitizer.go (line 246) only validates 5-6 field expressions
  4. cli/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
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
0 0 1 1 * 2025-2027 # Jan 1 at midnight, 2025-2027
0 0 1 1 * 2025 # Jan 1 at midnight, 2025

Copilot uses AI. Check for mistakes.
Comment on lines +78 to +82
# 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
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# 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

Copilot uses AI. Check for mistakes.
Merged via the queue into main with commit e1c606a Dec 26, 2025
33 checks passed
@CybotTM CybotTM deleted the feature/full-parser-support branch December 26, 2025 11:10
@CybotTM CybotTM added the released:v0.18.0 Released in v0.18.0 label Dec 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released:v0.18.0 Released in v0.18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants