stop timeout timers when no longer needed (#803)

This commit is contained in:
John Roesler 2024-12-11 10:43:27 -06:00 committed by GitHub
parent d856be5a41
commit 560a9dc9e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 4 deletions

4
job.go
View File

@ -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

View File

@ -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
}
}
@ -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
}
}