fix: make cron day job happen earlier (#17166)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2023-05-26 17:01:35 +08:00
committed by GitHub
co-authored by Qiu Jian
parent 7bf47eccde
commit 361616daa8
+10 -2
View File
@@ -61,7 +61,11 @@ type Timer2 struct {
func (t *Timer2) Next(now time.Time) time.Time {
next := now.Add(time.Hour * time.Duration(t.day) * 24)
return time.Date(next.Year(), next.Month(), next.Day(), t.hour, t.min, t.sec, 0, next.Location())
nextTime := time.Date(next.Year(), next.Month(), next.Day(), t.hour, t.min, t.sec, 0, next.Location())
if nextTime.Sub(now) > time.Duration(t.day)*time.Hour*24 {
nextTime = nextTime.Add(-time.Duration(t.day) * time.Hour * 24)
}
return nextTime
}
type TimerHour struct {
@@ -70,7 +74,11 @@ type TimerHour struct {
func (t *TimerHour) Next(now time.Time) time.Time {
next := now.Add(time.Hour * time.Duration(t.hour))
return time.Date(next.Year(), next.Month(), next.Day(), next.Hour(), t.min, t.sec, 0, next.Location())
nextTime := time.Date(next.Year(), next.Month(), next.Day(), next.Hour(), t.min, t.sec, 0, next.Location())
if nextTime.Sub(now) > time.Duration(t.hour)*time.Hour {
nextTime = nextTime.Add(-time.Duration(t.hour) * time.Hour)
}
return nextTime
}
type SCronJob struct {