Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix the bug that causes scheduled task running multiple times in a se…
…cond
  • Loading branch information
burakkoken committed Sep 27, 2022
commit ffb26088c55bc6d93fb490cfed04963275039122
18 changes: 15 additions & 3 deletions trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,27 @@ func (trigger *CronTrigger) NextExecutionTime(ctx TriggerContext) time.Time {
originalLocation := now.Location()

convertedTime := now.In(trigger.location)
newTime := time.Date(convertedTime.Year(),
convertedTime = time.Date(convertedTime.Year(),
convertedTime.Month(),
convertedTime.Day(),
convertedTime.Hour(),
convertedTime.Minute(),
convertedTime.Second(),
0,
convertedTime.Nanosecond(),
trigger.location)

next := trigger.cronExpression.NextTime(convertedTime)

// there is a bug causes timezone changing when an operation is performed on time value like add, subtraction
// to resolve this issue, we use a workaround solution
next = time.Date(next.Year(),
next.Month(),
next.Day(),
next.Hour(),
next.Minute(),
next.Second(),
next.Nanosecond(),
trigger.location)

next := trigger.cronExpression.NextTime(newTime)
return next.In(originalLocation)
}