Skip to content
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

dailyjob should not allow interval zero #791

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var (
ErrDailyJobAtTimeNil = fmt.Errorf("gocron: DailyJob: atTime within atTimes must not be nil")
ErrDailyJobAtTimesNil = fmt.Errorf("gocron: DailyJob: atTimes must not be nil")
ErrDailyJobHours = fmt.Errorf("gocron: DailyJob: atTimes hours must be between 0 and 23 inclusive")
ErrDailyJobZeroInterval = fmt.Errorf("gocron: DailyJob: interval must be greater than 0")
ErrDailyJobMinutesSeconds = fmt.Errorf("gocron: DailyJob: atTimes minutes and seconds must be between 0 and 59 inclusive")
ErrDurationJobIntervalZero = fmt.Errorf("gocron: DurationJob: time interval is 0")
ErrDurationRandomJobMinMax = fmt.Errorf("gocron: DurationRandomJob: minimum duration must be less than maximum duration")
Expand Down
4 changes: 4 additions & 0 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ func (d dailyJobDefinition) setup(j *internalJob, location *time.Location, _ tim
return ErrDailyJobMinutesSeconds
}

if d.interval == 0 {
return ErrDailyJobZeroInterval
}

ds := dailyJob{
interval: d.interval,
atTimes: atTimesDate,
Expand Down
11 changes: 11 additions & 0 deletions scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,17 @@ func TestScheduler_NewJobErrors(t *testing.T) {
nil,
ErrDailyJobMinutesSeconds,
},
{
"daily job interval 0",
DailyJob(
0,
NewAtTimes(
NewAtTime(1, 0, 0),
),
),
nil,
ErrDailyJobZeroInterval,
},
{
"weekly job at times nil",
WeeklyJob(
Expand Down