Change project layout to make easier debug / tests"
This commit is contained in:
17
vendor/github.com/go-co-op/gocron/v2/job.go
generated
vendored
17
vendor/github.com/go-co-op/gocron/v2/job.go
generated
vendored
@@ -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
|
||||
@@ -456,6 +459,8 @@ type oneTimeJobDefinition struct {
|
||||
func (o oneTimeJobDefinition) setup(j *internalJob, _ *time.Location, now time.Time) error {
|
||||
sortedTimes := o.startAt(j)
|
||||
slices.SortStableFunc(sortedTimes, ascendingTime)
|
||||
// deduplicate the times
|
||||
sortedTimes = removeSliceDuplicatesTimeOnSortedSlice(sortedTimes)
|
||||
// keep only schedules that are in the future
|
||||
idx, found := slices.BinarySearchFunc(sortedTimes, now, ascendingTime)
|
||||
if found {
|
||||
@@ -469,6 +474,16 @@ func (o oneTimeJobDefinition) setup(j *internalJob, _ *time.Location, now time.T
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeSliceDuplicatesTimeOnSortedSlice(times []time.Time) []time.Time {
|
||||
ret := make([]time.Time, 0, len(times))
|
||||
for i, t := range times {
|
||||
if i == 0 || t != times[i-1] {
|
||||
ret = append(ret, t)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// OneTimeJobStartAtOption defines when the one time job is run
|
||||
type OneTimeJobStartAtOption func(*internalJob) []time.Time
|
||||
|
||||
|
||||
Reference in New Issue
Block a user