Skip to content

Commit b48e680

Browse files
authored
Fix the bug that causes scheduled task running multiple times in a second (#19)
Fix the bug that causes scheduled task running multiple times in a second
1 parent 0b90d33 commit b48e680

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

trigger.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,27 @@ func (trigger *CronTrigger) NextExecutionTime(ctx TriggerContext) time.Time {
8181
originalLocation := now.Location()
8282

8383
convertedTime := now.In(trigger.location)
84-
newTime := time.Date(convertedTime.Year(),
84+
convertedTime = time.Date(convertedTime.Year(),
8585
convertedTime.Month(),
8686
convertedTime.Day(),
8787
convertedTime.Hour(),
8888
convertedTime.Minute(),
8989
convertedTime.Second(),
90-
0,
90+
convertedTime.Nanosecond(),
91+
trigger.location)
92+
93+
next := trigger.cronExpression.NextTime(convertedTime)
94+
95+
// there is a bug causes timezone changing when an operation is performed on time value like add, subtraction
96+
// to resolve this issue, we use a workaround solution
97+
next = time.Date(next.Year(),
98+
next.Month(),
99+
next.Day(),
100+
next.Hour(),
101+
next.Minute(),
102+
next.Second(),
103+
next.Nanosecond(),
91104
trigger.location)
92105

93-
next := trigger.cronExpression.NextTime(newTime)
94106
return next.In(originalLocation)
95107
}

0 commit comments

Comments
 (0)