Browse Source

En cours de développement

master
losyme 4 months ago
parent
commit
bbccc39d93
  1. 26
      workers/pool.go
  2. 4
      workers/supervisor.go

26
workers/pool.go

@ -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() {

4
workers/supervisor.go

@ -72,7 +72,9 @@ func (s *supervisor) start() {
s.zombie = zombie.Go(
1,
s.loop,
func(_ int) {
s.loop()
},
zombie.WithName("supervisor"),
zombie.WithLogger(s.logger),
)

Loading…
Cancel
Save