mirror of https://github.com/go-co-op/gocron.git
handle crontab and return error with invalid day in a month (#766)
This commit is contained in:
parent
68dba115b2
commit
3ccd68d676
|
|
@ -4,6 +4,7 @@ import "fmt"
|
|||
|
||||
// Public error definitions
|
||||
var (
|
||||
ErrCronJobInvalid = fmt.Errorf("gocron: CronJob: invalid crontab")
|
||||
ErrCronJobParse = fmt.Errorf("gocron: CronJob: crontab parse failure")
|
||||
ErrDailyJobAtTimeNil = fmt.Errorf("gocron: DailyJob: atTime within atTimes must not be nil")
|
||||
ErrDailyJobAtTimesNil = fmt.Errorf("gocron: DailyJob: atTimes must not be nil")
|
||||
|
|
|
|||
5
job.go
5
job.go
|
|
@ -116,7 +116,7 @@ type cronJobDefinition struct {
|
|||
withSeconds bool
|
||||
}
|
||||
|
||||
func (c cronJobDefinition) setup(j *internalJob, location *time.Location, _ time.Time) error {
|
||||
func (c cronJobDefinition) setup(j *internalJob, location *time.Location, now time.Time) error {
|
||||
var withLocation string
|
||||
if strings.HasPrefix(c.crontab, "TZ=") || strings.HasPrefix(c.crontab, "CRON_TZ=") {
|
||||
withLocation = c.crontab
|
||||
|
|
@ -140,6 +140,9 @@ func (c cronJobDefinition) setup(j *internalJob, location *time.Location, _ time
|
|||
if err != nil {
|
||||
return errors.Join(ErrCronJobParse, err)
|
||||
}
|
||||
if cronSchedule.Next(now).IsZero() {
|
||||
return ErrCronJobInvalid
|
||||
}
|
||||
|
||||
j.jobSchedule = &cronJob{cronSchedule: cronSchedule}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -532,6 +532,15 @@ func TestScheduler_NewJobErrors(t *testing.T) {
|
|||
nil,
|
||||
ErrCronJobParse,
|
||||
},
|
||||
{
|
||||
"cron invalid date",
|
||||
CronJob(
|
||||
"* * * 31 FEB *",
|
||||
true,
|
||||
),
|
||||
nil,
|
||||
ErrCronJobInvalid,
|
||||
},
|
||||
{
|
||||
"duration job time interval is zero",
|
||||
DurationJob(0 * time.Second),
|
||||
|
|
|
|||
Loading…
Reference in New Issue