Skip to content
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 @@ -59,6 +59,7 @@ var (
ErrStartTimeLaterThanEndTime = errors.New("gocron: WithStartDateTime: start must not be later than end")
ErrStopTimeEarlierThanStartTime = errors.New("gocron: WithStopDateTime: end must not be earlier than start")
ErrWithStopTimeoutZeroOrNegative = errors.New("gocron: WithStopTimeout: timeout must be greater than 0")
ErrWithLimitedRunsZero = errors.New("gocron: WithLimitedRuns: limit must be greater than 0")
)

// internal errors
Expand Down
3 changes: 3 additions & 0 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,9 @@ func WithEventListeners(eventListeners ...EventListener) JobOption {
// Upon reaching the limit, the job is removed from the scheduler.
func WithLimitedRuns(limit uint) JobOption {
return func(j *internalJob, _ time.Time) error {
if limit == 0 {
return ErrWithLimitedRunsZero
}
j.limitRunsTo = &limitRunsTo{
limit: limit,
runCount: 0,
Expand Down
8 changes: 8 additions & 0 deletions scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,14 @@ func TestScheduler_NewJobErrors(t *testing.T) {
[]JobOption{WithIdentifier(uuid.Nil)},
ErrWithIdentifierNil,
},
{
"WithLimitedRuns is zero",
DurationJob(
time.Second,
),
[]JobOption{WithLimitedRuns(0)},
ErrWithLimitedRunsZero,
},
}

for _, tt := range tests {
Expand Down