Skip to content

Commit

Permalink
dailyjob should not allow interval zero (#791)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRoesler authored Oct 31, 2024
1 parent 838bd51 commit 4baf341
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
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

0 comments on commit 4baf341

Please sign in to comment.