daily job next logic failed to consider 1 midnight attime (#635)
This commit is contained in:
@@ -622,12 +622,7 @@ type dailyJob struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d dailyJob) next(lastRun time.Time) time.Time {
|
func (d dailyJob) next(lastRun time.Time) time.Time {
|
||||||
next := d.nextDay(lastRun)
|
return d.nextDay(lastRun)
|
||||||
if !next.IsZero() {
|
|
||||||
return next
|
|
||||||
}
|
|
||||||
startNextDay := time.Date(lastRun.Year(), lastRun.Month(), lastRun.Day()+int(d.interval), 0, 0, 0, lastRun.Nanosecond(), lastRun.Location())
|
|
||||||
return d.nextDay(startNextDay)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d dailyJob) nextDay(lastRun time.Time) time.Time {
|
func (d dailyJob) nextDay(lastRun time.Time) time.Time {
|
||||||
@@ -643,6 +638,18 @@ func (d dailyJob) nextDay(lastRun time.Time) time.Time {
|
|||||||
return atDate
|
return atDate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
startNextDay := time.Date(lastRun.Year(), lastRun.Month(), lastRun.Day()+int(d.interval), 0, 0, 0, lastRun.Nanosecond(), lastRun.Location())
|
||||||
|
for _, at := range d.atTimes {
|
||||||
|
// sub the at time hour/min/sec onto the lastRun's values
|
||||||
|
// to use in checks to see if we've got our next run time
|
||||||
|
atDate := time.Date(startNextDay.Year(), startNextDay.Month(), startNextDay.Day(), at.Hour(), at.Minute(), at.Second(), startNextDay.Nanosecond(), startNextDay.Location())
|
||||||
|
|
||||||
|
if !atDate.Before(startNextDay) {
|
||||||
|
// now that we're looking at the next day, it's ok to consider
|
||||||
|
// the same at time that was last run
|
||||||
|
return atDate
|
||||||
|
}
|
||||||
|
}
|
||||||
return time.Time{}
|
return time.Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
@@ -50,6 +50,16 @@ func TestDailyJob_next(t *testing.T) {
|
|||||||
expectedNextRun time.Time
|
expectedNextRun time.Time
|
||||||
expectedDurationToNextRun time.Duration
|
expectedDurationToNextRun time.Duration
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
"daily at midnight",
|
||||||
|
1,
|
||||||
|
[]time.Time{
|
||||||
|
time.Date(0, 0, 0, 0, 0, 0, 0, time.UTC),
|
||||||
|
},
|
||||||
|
time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
|
time.Date(2000, 1, 2, 0, 0, 0, 0, time.UTC),
|
||||||
|
24 * time.Hour,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"daily multiple at times",
|
"daily multiple at times",
|
||||||
1,
|
1,
|
||||||
|
|||||||
Reference in New Issue
Block a user