Skip to content

Commit e1c606a

Browse files
authored
feat(scheduler): use go-cron FullParser for extended cron syntax (#438)
## Summary Switch from custom parser configuration to `cron.FullParser()` which enables all cron syntax variants: - 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.) ## 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 ```bash # 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 - [x] Existing tests pass (`make test`) - [x] go-cron v0.8.0 includes comprehensive FullParser tests - [ ] Manual verification of year field scheduling
2 parents 1b1b5f9 + 0eeea8d commit e1c606a

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

core/scheduler.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ func NewSchedulerWithClock(l Logger, cronClock *CronClock) *Scheduler {
7373
func newSchedulerInternal(l Logger, metricsRecorder MetricsRecorder, minEveryInterval time.Duration, cronClock *CronClock) *Scheduler {
7474
cronUtils := NewCronUtils(l)
7575

76-
parser := cron.MustNewParser(
77-
cron.SecondOptional | cron.Minute | cron.Hour |
78-
cron.Dom | cron.Month | cron.Dow | cron.Descriptor,
79-
)
76+
parser := cron.FullParser()
8077
if minEveryInterval != 0 {
8178
parser = parser.WithMinEveryInterval(minEveryInterval)
8279
}

docs/QUICK_REFERENCE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ export OFELIA_PPROF_ADDRESS=127.0.0.1:8080
7070
0 0 */4 * * * # Every 4 hours
7171
0 */30 * * * * # Every 30 minutes
7272

73+
# With year field (one-time scheduling)
74+
30 14 25 12 * 2025 # Dec 25, 2025 at 14:30 (one-time job)
75+
0 30 14 25 12 * 2025 # Same with seconds field
76+
0 0 1 1 * 2025-2027 # Jan 1 at midnight, 2025-2027
77+
78+
# Extended syntax (L, W, #)
79+
0 12 L * * # Last day of every month at noon
80+
0 12 15W * * # Nearest weekday to 15th at noon
81+
0 12 * * FRI#3 # 3rd Friday of every month at noon
82+
0 12 * * FRI#L # Last Friday of every month at noon
83+
7384
# Descriptors
7485
@yearly # 0 0 1 1 *
7586
@annually # 0 0 1 1 *

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/jessevdk/go-flags v1.6.1
1919
github.com/manifoldco/promptui v0.9.0
2020
github.com/mitchellh/mapstructure v1.5.0
21-
github.com/netresearch/go-cron v0.7.1
21+
github.com/netresearch/go-cron v0.8.0
2222
github.com/opencontainers/image-spec v1.1.1
2323
github.com/sirupsen/logrus v1.9.3
2424
github.com/stretchr/testify v1.11.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ github.com/moby/term v0.5.2 h1:6qk3FJAFDs6i/q3W/pQ97SX192qKfZgGjCQqfCJkgzQ=
109109
github.com/moby/term v0.5.2/go.mod h1:d3djjFCrjnB+fl8NJux+EJzu0msscUP+f8it8hPkFLc=
110110
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
111111
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
112-
github.com/netresearch/go-cron v0.7.1 h1:4uhkNSWTR3mBVlY1JtIcnZEaSLirTwkLksKy+fXgJw4=
113-
github.com/netresearch/go-cron v0.7.1/go.mod h1:oRPUA7fHC/ul86n+d3SdUD54cEuHIuCLiFJCua5a5/E=
112+
github.com/netresearch/go-cron v0.8.0 h1:2kgxsBMAFONMWQvhFbFIlc1xO6upNs/jJ7D7OAFzKmw=
113+
github.com/netresearch/go-cron v0.8.0/go.mod h1:oRPUA7fHC/ul86n+d3SdUD54cEuHIuCLiFJCua5a5/E=
114114
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
115115
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
116116
github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040=

0 commit comments

Comments
 (0)