|
|
|
@ -31,6 +31,11 @@ func newPool(cfg *Config, state *state) *pool {
|
|
|
|
|
fqdn = "?" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
zombie := zombie.NewGWithContext( |
|
|
|
|
context.Background(), |
|
|
|
|
zombie.WithLogger(cfg.Logger), |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
return &pool{ |
|
|
|
|
host: fqdn, |
|
|
|
|
model: cfg.Model, |
|
|
|
@ -39,6 +44,7 @@ func newPool(cfg *Config, state *state) *pool {
|
|
|
|
|
state: state, |
|
|
|
|
workers: make(map[string]*worker), |
|
|
|
|
stopCh: make(chan bool, _maxPoolSize), |
|
|
|
|
zombie: zombie, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -48,21 +54,15 @@ func (p *pool) size() int {
|
|
|
|
|
|
|
|
|
|
func (p *pool) startOneWorker(stoppedCh chan<- string) { |
|
|
|
|
worker := newWorker(p.host, p.model, p.runner, p.logger, p.state) |
|
|
|
|
fn := func(ctx context.Context) { worker.run(ctx, p.stopCh, stoppedCh) } |
|
|
|
|
|
|
|
|
|
p.workers[worker.id] = worker |
|
|
|
|
|
|
|
|
|
if p.zombie == nil { |
|
|
|
|
p.zombie = zombie.GoWithContext( |
|
|
|
|
context.Background(), |
|
|
|
|
1, |
|
|
|
|
fn, |
|
|
|
|
zombie.WithName("worker"), |
|
|
|
|
zombie.WithLogger(p.logger), |
|
|
|
|
) |
|
|
|
|
} else { |
|
|
|
|
p.zombie.Go(1, fn) |
|
|
|
|
} |
|
|
|
|
p.zombie.Go( |
|
|
|
|
1, |
|
|
|
|
func(ctx context.Context, _ int) { |
|
|
|
|
worker.run(ctx, p.stopCh, stoppedCh) |
|
|
|
|
}, |
|
|
|
|
"worker", |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (p *pool) stopOneWorker() { |
|
|
|
|