mirror of https://github.com/go-co-op/gocron.git
fix: limit validation for WithLimitedRuns
This commit is contained in:
parent
4278ff74b4
commit
fe46434d6f
|
|
@ -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
|
||||
|
|
|
|||
3
job.go
3
job.go
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue