diff options
author | Wolfy-J <[email protected]> | 2019-05-04 19:20:17 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2019-05-04 19:20:17 +0300 |
commit | 726b31008e73ab83d0582305c28a8cf62322e47a (patch) | |
tree | e83debd4f58211c5372a1b1a25399c4066d62542 /service | |
parent | 325fcb1819fae87699676dfe3ced21c40917b90f (diff) |
cyclo fix
Diffstat (limited to 'service')
-rw-r--r-- | service/watcher/watcher.go | 66 |
1 files changed, 35 insertions, 31 deletions
diff --git a/service/watcher/watcher.go b/service/watcher/watcher.go index 788ee703..65a2eeeb 100644 --- a/service/watcher/watcher.go +++ b/service/watcher/watcher.go @@ -52,6 +52,41 @@ type watcher struct { // watch the pool state func (wch *watcher) watch(p roadrunner.Pool) { + wch.loadWorkers(p) + + now := time.Now() + + if wch.cfg.MaxExecTTL != 0 { + for _, w := range wch.sw.find( + roadrunner.StateWorking, + now.Add(-time.Second*time.Duration(wch.cfg.MaxExecTTL)), + ) { + eID := w.State().NumExecs() + err := fmt.Errorf("max exec time reached (%vs)", wch.cfg.MaxExecTTL) + + // make sure worker still on initial request + if p.Remove(w, err) && w.State().NumExecs() == eID { + go w.Kill() + wch.report(EventMaxExecTTL, w, err) + } + } + } + + // locale workers which are in idle mode for too long + if wch.cfg.MaxIdleTTL != 0 { + for _, w := range wch.sw.find( + roadrunner.StateReady, + now.Add(-time.Second*time.Duration(wch.cfg.MaxIdleTTL)), + ) { + err := fmt.Errorf("max idle time reached (%vs)", wch.cfg.MaxIdleTTL) + if p.Remove(w, err) { + wch.report(EventMaxIdleTTL, w, err) + } + } + } +} + +func (wch *watcher) loadWorkers(p roadrunner.Pool) { now := time.Now() for _, w := range p.Workers() { @@ -86,37 +121,6 @@ func (wch *watcher) watch(p roadrunner.Pool) { } wch.sw.sync(now) - - if wch.cfg.MaxExecTTL != 0 { - for _, w := range wch.sw.find( - roadrunner.StateWorking, - now.Add(-time.Second*time.Duration(wch.cfg.MaxExecTTL)), - ) { - eID := w.State().NumExecs() - err := fmt.Errorf("max exec time reached (%vs)", wch.cfg.MaxExecTTL) - - if p.Remove(w, err) { - // make sure worker still on initial request - if w.State().NumExecs() == eID { - go w.Kill() - wch.report(EventMaxExecTTL, w, err) - } - } - } - } - - // locale workers which are in idle mode for too long - if wch.cfg.MaxIdleTTL != 0 { - for _, w := range wch.sw.find( - roadrunner.StateReady, - now.Add(-time.Second*time.Duration(wch.cfg.MaxIdleTTL)), - ) { - err := fmt.Errorf("max idle time reached (%vs)", wch.cfg.MaxIdleTTL) - if p.Remove(w, err) { - wch.report(EventMaxIdleTTL, w, err) - } - } - } } // throw watcher event |