webhookd/pkg/worker/dispatcher.go
Nicolas Carlier 14c214efdf refactor(): Complete refactoring.
- No external dependencies
- No predefined directory structure
- Able to launch any kind of shell script with custom parameters
- Get script output as text event stream (SSE)
- Using common Makefiles
- Extends docker/dind Docker image
2018-01-02 16:11:59 +00:00

35 lines
771 B
Go

package worker
import "log"
var WorkerQueue chan chan WorkRequest
var WorkQueue = make(chan WorkRequest, 100)
// StartDispatcher is charged to start n workers.
func StartDispatcher(nworkers int) {
// First, initialize the channel we are going to but the workers' work channels into.
WorkerQueue = make(chan chan WorkRequest, nworkers)
// Now, create all of our workers.
for i := 0; i < nworkers; i++ {
log.Println("Starting worker", i+1)
worker := NewWorker(i+1, WorkerQueue)
worker.Start()
}
go func() {
for {
select {
case work := <-WorkQueue:
log.Println("Received work request:", work.Name)
go func() {
worker := <-WorkerQueue
log.Println("Dispatching work request:", work.Name)
worker <- work
}()
}
}
}()
}