File tree 3 files changed +32
-0
lines changed
3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 21
21
ErrMonthlyJobAtTimesNil = fmt .Errorf ("gocron: MonthlyJob: atTimes must not be nil" )
22
22
ErrMonthlyJobDaysNil = fmt .Errorf ("gocron: MonthlyJob: daysOfTheMonth must not be nil" )
23
23
ErrMonthlyJobHours = fmt .Errorf ("gocron: MonthlyJob: atTimes hours must be between 0 and 23 inclusive" )
24
+ ErrMonthlyJobZeroInterval = fmt .Errorf ("gocron: MonthlyJob: interval must be greater than 0" )
24
25
ErrMonthlyJobMinutesSeconds = fmt .Errorf ("gocron: MonthlyJob: atTimes minutes and seconds must be between 0 and 59 inclusive" )
25
26
ErrNewJobTaskNil = fmt .Errorf ("gocron: NewJob: Task must not be nil" )
26
27
ErrNewJobTaskNotFunc = fmt .Errorf ("gocron: NewJob: Task.Function must be of kind reflect.Func" )
34
35
ErrWeeklyJobAtTimesNil = fmt .Errorf ("gocron: WeeklyJob: atTimes must not be nil" )
35
36
ErrWeeklyJobDaysOfTheWeekNil = fmt .Errorf ("gocron: WeeklyJob: daysOfTheWeek must not be nil" )
36
37
ErrWeeklyJobHours = fmt .Errorf ("gocron: WeeklyJob: atTimes hours must be between 0 and 23 inclusive" )
38
+ ErrWeeklyJobZeroInterval = fmt .Errorf ("gocron: WeeklyJob: interval must be greater than 0" )
37
39
ErrWeeklyJobMinutesSeconds = fmt .Errorf ("gocron: WeeklyJob: atTimes minutes and seconds must be between 0 and 59 inclusive" )
38
40
ErrPanicRecovered = fmt .Errorf ("gocron: panic recovered" )
39
41
ErrWithClockNil = fmt .Errorf ("gocron: WithClock: clock must not be nil" )
Original file line number Diff line number Diff line change @@ -274,6 +274,9 @@ type weeklyJobDefinition struct {
274
274
275
275
func (w weeklyJobDefinition ) setup (j * internalJob , location * time.Location , _ time.Time ) error {
276
276
var ws weeklyJob
277
+ if w .interval == 0 {
278
+ return ErrWeeklyJobZeroInterval
279
+ }
277
280
ws .interval = w .interval
278
281
279
282
if w .daysOfTheWeek == nil {
@@ -339,6 +342,9 @@ type monthlyJobDefinition struct {
339
342
340
343
func (m monthlyJobDefinition ) setup (j * internalJob , location * time.Location , _ time.Time ) error {
341
344
var ms monthlyJob
345
+ if m .interval == 0 {
346
+ return ErrMonthlyJobZeroInterval
347
+ }
342
348
ms .interval = m .interval
343
349
344
350
if m .daysOfTheMonth == nil {
Original file line number Diff line number Diff line change @@ -686,6 +686,18 @@ func TestScheduler_NewJobErrors(t *testing.T) {
686
686
nil ,
687
687
ErrWeeklyJobMinutesSeconds ,
688
688
},
689
+ {
690
+ "weekly job interval zero" ,
691
+ WeeklyJob (
692
+ 0 ,
693
+ NewWeekdays (time .Monday ),
694
+ NewAtTimes (
695
+ NewAtTime (1 , 0 , 0 ),
696
+ ),
697
+ ),
698
+ nil ,
699
+ ErrWeeklyJobZeroInterval ,
700
+ },
689
701
{
690
702
"monthly job at times nil" ,
691
703
MonthlyJob (
@@ -766,6 +778,18 @@ func TestScheduler_NewJobErrors(t *testing.T) {
766
778
nil ,
767
779
ErrMonthlyJobMinutesSeconds ,
768
780
},
781
+ {
782
+ "monthly job interval zero" ,
783
+ MonthlyJob (
784
+ 0 ,
785
+ NewDaysOfTheMonth (1 ),
786
+ NewAtTimes (
787
+ NewAtTime (1 , 0 , 0 ),
788
+ ),
789
+ ),
790
+ nil ,
791
+ ErrMonthlyJobZeroInterval ,
792
+ },
769
793
{
770
794
"WithName no name" ,
771
795
DurationJob (
You can’t perform that action at this time.
0 commit comments