diff options
Diffstat (limited to 'static_pool.go')
-rw-r--r-- | static_pool.go | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/static_pool.go b/static_pool.go index 73caf841..04f08d24 100644 --- a/static_pool.go +++ b/static_pool.go @@ -111,18 +111,18 @@ func (p *StaticPool) Exec(rqs *Payload) (rsp *Payload, err error) { return nil, err } - go p.Replace(w, err) + go p.replaceWorker(w, err) return nil, err } // worker want's to be terminated if rsp.Body == nil && rsp.Context != nil && string(rsp.Context) == StopRequest { - go p.Replace(w, err) + go p.replaceWorker(w, err) return p.Exec(rqs) } if p.cfg.MaxExecutions != 0 && w.State().NumExecs() >= p.cfg.MaxExecutions { - go p.Replace(w, p.cfg.MaxExecutions) + go p.replaceWorker(w, p.cfg.MaxExecutions) } else { p.free <- w } @@ -130,22 +130,6 @@ func (p *StaticPool) Exec(rqs *Payload) (rsp *Payload, err error) { return rsp, nil } -// Replace replaces dead or expired worker with new instance. -func (p *StaticPool) Replace(w *Worker, caused interface{}) { - go p.destroyWorker(w) - - if nw, err := p.createWorker(); err != nil { - p.throw(EventError, w, err) - - if len(p.Workers()) == 0 { - // possible situation when major error causes all PHP scripts to die (for example dead DB) - p.throw(EventError, nil, fmt.Errorf("all workers dead")) - } - } else { - p.free <- nw - } -} - // Destroy all underlying workers (but let them to complete the task). func (p *StaticPool) Destroy() { p.tasks.Wait() @@ -182,6 +166,22 @@ func (p *StaticPool) allocateWorker() (w *Worker, err error) { } } +// replaceWorker replaces dead or expired worker with new instance. +func (p *StaticPool) replaceWorker(w *Worker, caused interface{}) { + go p.destroyWorker(w) + + if nw, err := p.createWorker(); err != nil { + p.throw(EventError, w, err) + + if len(p.Workers()) == 0 { + // possible situation when major error causes all PHP scripts to die (for example dead DB) + p.throw(EventError, nil, fmt.Errorf("all workers dead")) + } + } else { + p.free <- nw + } +} + // destroyWorker destroys workers and removes it from the pool. func (p *StaticPool) destroyWorker(w *Worker) { p.throw(EventDestruct, w, nil) |