Clear workerInput channel after done event

This commit is contained in:
Holger Obermaier 2022-04-20 12:36:45 +02:00
parent 8c73095548
commit c2d4272fdf

View File

@ -50,7 +50,18 @@ func (r *RedfishReceiver) Start() {
// Connect to redfish service // Connect to redfish service
c, err := gofish.Connect(clientConfig.gofish) c, err := gofish.Connect(clientConfig.gofish)
if err != nil { if err != nil {
return fmt.Errorf("readPowerMetric: gofish.Connect(...) failed: %v", err) c := struct {
Username string
Endpoint string
BasicAuth bool
Insecure bool
}{
Username: clientConfig.gofish.Username,
Endpoint: clientConfig.gofish.Endpoint,
BasicAuth: clientConfig.gofish.BasicAuth,
Insecure: clientConfig.gofish.Insecure,
}
return fmt.Errorf("readPowerMetric: gofish.Connect(%+v) failed: %v", c, err)
} }
defer c.Logout() defer c.Logout()
@ -146,18 +157,19 @@ func (r *RedfishReceiver) Start() {
} }
// Distribute client configs to workers // Distribute client configs to workers
clientConfigLoop:
for i := range r.config.ClientConfigs { for i := range r.config.ClientConfigs {
// Check done channel status // Check done channel status
select { select {
case _, ok := <-r.done: case workerInput <- i:
if !ok { case <-r.done:
break clientConfigLoop // process done event
// Stop workers, clear channel and wait for all workers to finish
close(workerInput)
for range workerInput {
} }
default: workerWaitGroup.Wait()
return
} }
workerInput <- i
} }
// Stop workers and wait for all workers to finish // Stop workers and wait for all workers to finish