Skip to content

Commit

Permalink
stop timeout timers when no longer needed
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRoesler committed Dec 11, 2024
1 parent d856be5 commit 981161e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion job.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,12 +1099,14 @@ func (j job) RunNow() error {
defer cancel()
resp := make(chan error, 1)

t := time.NewTimer(100 * time.Millisecond)
select {
case j.runJobRequest <- runJobRequest{
id: j.id,
outChan: resp,
}:
case <-time.After(100 * time.Millisecond):
t.Stop()
case <-t.C:
return ErrJobRunNowFailed
}
var err error
Expand Down
15 changes: 12 additions & 3 deletions scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,11 @@ func (s *scheduler) stopScheduler() {
}
var err error
if s.started {
t := time.NewTimer(s.exec.stopTimeout + 1*time.Second)
select {
case err = <-s.exec.done:
case <-time.After(s.exec.stopTimeout + 1*time.Second):
t.Stop()
case <-t.C:
err = ErrStopExecutorTimedOut
}
}
Expand Down Expand Up @@ -741,20 +743,27 @@ func (s *scheduler) StopJobs() error {
return nil
case s.stopCh <- struct{}{}:
}

t := time.NewTimer(s.exec.stopTimeout + 2*time.Second)
select {
case err := <-s.stopErrCh:
t.Stop()
return err
case <-time.After(s.exec.stopTimeout + 2*time.Second):
case <-t.C:
return ErrStopSchedulerTimedOut
}
}

func (s *scheduler) Shutdown() error {
s.shutdownCancel()

t := time.NewTimer(s.exec.stopTimeout + 2*time.Second)
select {
case err := <-s.stopErrCh:

t.Stop()
return err
case <-time.After(s.exec.stopTimeout + 2*time.Second):
case <-t.C:
return ErrStopSchedulerTimedOut
}
}
Expand Down

0 comments on commit 981161e

Please sign in to comment.