mirror of https://github.com/go-co-op/gocron.git
stop timeout timers when no longer needed (#803)
This commit is contained in:
parent
d856be5a41
commit
560a9dc9e4
4
job.go
4
job.go
|
|
@ -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
|
||||
|
|
|
|||
15
scheduler.go
15
scheduler.go
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue