MCPcopy Create free account
hub / github.com/PostHog/duckgres / SpawnAll

Method SpawnAll

controlplane/worker_mgr.go:638–668  ·  view source on GitHub ↗

SpawnAll spawns the specified number of workers in parallel.

(count int)

Source from the content-addressed store, hash-verified

636 stream, err := client.Client.DoAction(ctx, &flight.Action{Type: "HealthCheck", Body: body})
637 if err != nil {
638 return nil, fmt.Errorf("health check action: %w", err)
639 }
640
641 msg, err := stream.Recv()
642 if err != nil {
643 return nil, fmt.Errorf("health check recv: %w", err)
644 }
645
646 var result healthCheckResult
647 if err := json.Unmarshal(msg.Body, &result); err != nil {
648 return nil, fmt.Errorf("health check unmarshal: %w", err)
649 }
650 return &result, nil
651}
652
653// Worker returns a worker by ID.
654func (p *FlightWorkerPool) Worker(id int) (*ManagedWorker, bool) {
655 p.mu.RLock()
656 defer p.mu.RUnlock()
657 w, ok := p.workers[id]
658 return w, ok
659}
660
661// SpawnAll spawns the specified number of workers in parallel.
662func (p *FlightWorkerPool) SpawnAll(count int) error {
663 var wg sync.WaitGroup
664 errs := make(chan error, count)
665
666 for i := 0; i < count; i++ {
667 wg.Add(1)
668 go func(id int) {
669 defer wg.Done()
670 if err := p.SpawnWorker(id); err != nil {
671 errs <- err

Callers 1

SpawnMinWorkersMethod · 0.95

Calls 2

SpawnWorkerMethod · 0.95
AddMethod · 0.80

Tested by

no test coverage detected