mirror of
				https://github.com/ClusterCockpit/cc-metric-collector.git
				synced 2025-10-31 00:55:06 +01:00 
			
		
		
		
	Clear workerInput channel after done event
This commit is contained in:
		| @@ -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 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user