From d4b52bb35417c464755af95366243e65b6cdc836 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Sun, 28 Jan 2018 15:01:01 +0300 Subject: minor CS --- pool.go | 28 ++++++++++++---------------- todo.go | 3 ++- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/pool.go b/pool.go index ec508c93..7abfe7b2 100644 --- a/pool.go +++ b/pool.go @@ -52,8 +52,6 @@ func NewPool(cmd func() *exec.Cmd, factory Factory, cfg Config) (*Pool, error) { free: make(chan *Worker, cfg.NumWorkers), } - //todo: watch for error from workers!!! - // constant number of workers simplify logic for i := uint64(0); i < p.cfg.NumWorkers; i++ { // to test if worker ready @@ -61,21 +59,9 @@ func NewPool(cmd func() *exec.Cmd, factory Factory, cfg Config) (*Pool, error) { if err != nil { p.Destroy() - return nil, err } - // worker watcher - go func(w *Worker) { - if err := w.Wait(); err != nil { - - // todo: register error - log.Println(err) - - //todo: automatic replace - } - }(w) - p.free <- w } @@ -198,10 +184,10 @@ func (p *Pool) destroyWorker(w *Worker) { select { case <-w.waitDone: // worker is dead - case <-time.NewTimer(time.Second * 10).C: + case <-time.NewTimer(p.cfg.DestroyTimeout).C: // failed to stop process if err := w.Kill(); err != nil { - //todo: can't kill or already killed? + // todo: handle error } } } @@ -214,6 +200,16 @@ func (p *Pool) createWorker() (*Worker, error) { return nil, err } + go func(w *Worker) { + if err := w.Wait(); err != nil { + // todo: register error + + log.Println(err) + + //todo: automatic replace + } + }(w) + p.muw.Lock() defer p.muw.Unlock() diff --git a/todo.go b/todo.go index 68340370..d3af4a44 100644 --- a/todo.go +++ b/todo.go @@ -3,4 +3,5 @@ package roadrunner // test terminate request // test head -// test json head? \ No newline at end of file +// test json head? +// job error \ No newline at end of file -- cgit v1.2.3