-
-
Notifications
You must be signed in to change notification settings - Fork 222
feat: add optional seconds field to cron schedule parsing #1510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: add optional seconds field to cron schedule parsing #1510
Conversation
Enables sub-minute scheduling by adding SecondOptional to the cron parser. This allows schedules like '*/5 * * * * *' to run every 5 seconds. Changes: - Add cron.SecondOptional flag to parser in spec/schedule.go - Update scheduler tick precision from minute to second - Update NextTick to advance by seconds instead of minutes - Update dagrunjob to use second-level truncation Fixes dagu-org#676
📝 WalkthroughWalkthroughThe changes enable second-level precision in cron expressions by adding Changes
Poem
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (5)
🧰 Additional context used📓 Path-based instructions (2)**/*.go📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*_test.go📄 CodeRabbit inference engine (AGENTS.md)
Files:
🔇 Additional comments (7)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/service/scheduler/scheduler_test.go (1)
71-80: Critical: Test expectations don't match new second-based behavior.The
NextTicktest expects minute-granularity behavior (advancing from01:00:50to01:01:00), but the implementation now uses second-granularity (NextTickreturnsnow.Add(time.Second).Truncate(time.Second)), which would advance to01:00:51.This test should be failing unless the expected result is updated to match the new second-based tick advancement.
🔎 Proposed fix
t.Run("NextTick", func(t *testing.T) { now := time.Date(2020, 1, 1, 1, 0, 50, 0, time.UTC) th := test.SetupScheduler(t) schedulerInstance, err := scheduler.New(th.Config, &mockJobManager{}, th.DAGRunMgr, th.DAGRunStore, th.QueueStore, th.ProcStore, th.ServiceRegistry, th.CoordinatorCli) require.NoError(t, err) next := schedulerInstance.NextTick(now) - require.Equal(t, time.Date(2020, 1, 1, 1, 1, 0, 0, time.UTC), next) + require.Equal(t, time.Date(2020, 1, 1, 1, 0, 51, 0, time.UTC), next) })
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
.gitignoreinternal/core/spec/schedule.gointernal/service/scheduler/dagrunjob.gointernal/service/scheduler/scheduler.gointernal/service/scheduler/scheduler_test.go
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go
📄 CodeRabbit inference engine (AGENTS.md)
**/*.go: Backend entrypoint incmd/orchestrates the scheduler and CLI; runtime, persistence, and service layers sit underinternal/*(for exampleinternal/runtime,internal/persistence)
Keep Go filesgofmt/goimportsclean; use tabs, PascalCase for exported symbols (SchedulerClient), lowerCamelCase for locals, andErr...names for package-level errors
Repository linting relies ongolangci-lint; prefer idiomatic Go patterns, minimal global state, and structured logging helpers ininternal/common
Files:
internal/core/spec/schedule.gointernal/service/scheduler/scheduler.gointernal/service/scheduler/scheduler_test.gointernal/service/scheduler/dagrunjob.go
**/*_test.go
📄 CodeRabbit inference engine (AGENTS.md)
**/*_test.go: Co-locate Go tests as*_test.go; favour table-driven cases and cover failure paths
Usestretchr/testify/requireand shared fixtures frominternal/testinstead of duplicating mocks
Files:
internal/service/scheduler/scheduler_test.go
🔇 Additional comments (7)
.gitignore (1)
41-41: LGTM! Standard build artifact ignore.Adding the
dagubinary to.gitignoreprevents committing the built executable.internal/service/scheduler/dagrunjob.go (1)
96-96: LGTM! Necessary precision adjustment.Changing from
time.Minutetotime.Secondtruncation aligns with the scheduler's new second-level tick granularity, ensuring correct comparisons for sub-minute schedules.internal/service/scheduler/scheduler_test.go (2)
84-84: LGTM! Test parser aligned with production.Correctly updated to include
cron.SecondOptionalflag, matching the production parser configuration.
195-195: LGTM! Test parser aligned with production.Correctly updated to include
cron.SecondOptionalflag, matching the production parser configuration.internal/service/scheduler/scheduler.go (2)
309-311: LGTM! Correct second-based tick advancement.The
NextTickimplementation now correctly advances by one second instead of one minute, aligning with the second-level scheduling granularity introduced bycron.SecondOptional.
283-283: Verify performance impact of second-level tick granularity.Changing from
time.Minutetotime.Secondtruncation means the scheduler now ticks 60 times more frequently. This is necessary for sub-minute scheduling but increases CPU usage.The impact should be minimal when no jobs are scheduled for a given second, but for deployments with many DAGs, the increased frequency of
invokeJobsandentryReader.Nextcalls could be noticeable.Consider profiling the scheduler under production-like load to verify the performance impact is acceptable:
#!/bin/bash # Compare CPU usage before/after this change with a representative DAG count echo "Profile the scheduler with multiple DAGs scheduled at different intervals:" echo "1. Set up test environment with 100+ DAGs (mix of minute and second schedules)" echo "2. Monitor CPU usage over 5-10 minutes" echo "3. Compare against baseline with minute-only schedules" echo "" echo "Use Go's pprof if available:" echo " go tool pprof -http=:8080 http://localhost:6060/debug/pprof/profile?seconds=30"internal/core/spec/schedule.go (1)
10-12: Thecron.SecondOptionalflag correctly enables optional seconds parsing.The addition of
cron.SecondOptionalto the parser flags allows both 5-field (minute precision) and 6-field (second precision) cron expressions while maintaining backward compatibility. This is the standard approach in robfig/cron v3.0.1 for supporting sub-minute scheduling as intended by the PR.
Summary
Enables sub-minute scheduling by adding
SecondOptionalto the cron parser. This allows schedules like*/5 * * * * *to run every 5 seconds.Changes
cron.SecondOptionalflag to parser inspec/schedule.goNextTickto advance by seconds instead of minutesdagrunjobto use second-level truncationMotivation
As discussed in #676, the underlying
robfig/cronlibrary already supports seconds parsing via theSecondOptionalflag. This PR enables that functionality.Usage
Standard 5-field cron expressions continue to work as before:
With this change, 6-field expressions with seconds are now supported:
Fixes #676
Summary by CodeRabbit
New Features
Chores
✏️ Tip: You can customize this high-level summary in your review settings.