Skip to content

Commit

Permalink
Optimize job setTimer (#363)
Browse files Browse the repository at this point in the history
* fix: use Scheduler.time.now() instead of time.Now()

* perf: optimize job timer
  • Loading branch information
fufuok committed Aug 1, 2022
1 parent c667f33 commit 22fc237
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion scheduler.go
Expand Up @@ -569,9 +569,11 @@ func (s *Scheduler) runContinuous(job *Job) {
job.setTimer(time.AfterFunc(next.duration, func() {
if !next.dateTime.IsZero() {
for {
if time.Now().Unix() >= next.dateTime.Unix() {
n := s.now().UnixNano() - next.dateTime.UnixNano()
if n >= 0 {
break
}
s.time.Sleep(time.Duration(n))
}
}
s.runContinuous(job)
Expand Down

0 comments on commit 22fc237

Please sign in to comment.