| 41 | } |
| 42 | |
| 43 | func NewWorkerPool(name string, numWorkers int, reg prometheus.Registerer) AsyncExecutor { |
| 44 | wp := &workerPoolExecutor{ |
| 45 | serverWorkerChannel: make(chan func()), |
| 46 | fallbackTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{ |
| 47 | Namespace: "cortex", |
| 48 | Name: "worker_pool_fallback_total", |
| 49 | Help: "The total number additional go routines that needed to be created to run jobs.", |
| 50 | ConstLabels: prometheus.Labels{"name": name}, |
| 51 | }), |
| 52 | } |
| 53 | |
| 54 | for range numWorkers { |
| 55 | go wp.run() |
| 56 | } |
| 57 | |
| 58 | return wp |
| 59 | } |
| 60 | |
| 61 | func (s *workerPoolExecutor) Stop() { |
| 62 | s.closeOnce.Do(func() { |