mirror of
https://github.com/ncarlier/webhookd.git
synced 2025-04-07 21:47:09 +00:00

- URL based configuration - Only prefixed output lines are notified - HTTP notifier: send a JSON with notification in the text attribute - SMTP notifier: send an email with notification text in body
40 lines
951 B
Go
40 lines
951 B
Go
package worker
|
|
|
|
import (
|
|
"github.com/ncarlier/webhookd/pkg/logger"
|
|
"github.com/ncarlier/webhookd/pkg/model"
|
|
)
|
|
|
|
// WorkerQueue is the gloabl queue of Workers
|
|
var WorkerQueue chan chan model.WorkRequest
|
|
|
|
// WorkQueue is the global queue of work to dispatch
|
|
var WorkQueue = make(chan model.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 model.WorkRequest, nworkers)
|
|
|
|
// Now, create all of our workers.
|
|
for i := 0; i < nworkers; i++ {
|
|
logger.Debug.Println("Starting worker", i+1)
|
|
worker := NewWorker(i+1, WorkerQueue)
|
|
worker.Start()
|
|
}
|
|
|
|
go func() {
|
|
for {
|
|
select {
|
|
case work := <-WorkQueue:
|
|
go func() {
|
|
worker := <-WorkerQueue
|
|
|
|
logger.Debug.Printf("Dispatching work request: %s#%d", work.Name, work.ID)
|
|
worker <- work
|
|
}()
|
|
}
|
|
}
|
|
}()
|
|
}
|