mirror of
https://github.com/ncarlier/webhookd.git
synced 2025-04-15 02:51:50 +00:00

- 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
35 lines
771 B
Go
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
|
|
}()
|
|
}
|
|
}
|
|
}()
|
|
}
|