mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
refactor: move more background jobs to using job queue
This commit is contained in:
@@ -2,25 +2,33 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/emvi/logbuch"
|
||||
"github.com/muety/artifex"
|
||||
"math"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
var jobqueues map[string]*artifex.Dispatcher
|
||||
|
||||
const (
|
||||
QueueDefault = ""
|
||||
QueueProcessing = "processing"
|
||||
QueueMails = "mails"
|
||||
QueueDefault = "wakapi.default"
|
||||
QueueProcessing = "wakapi.processing"
|
||||
QueueReports = "wakapi.reports"
|
||||
)
|
||||
|
||||
func init() {
|
||||
jobqueues = make(map[string]*artifex.Dispatcher)
|
||||
|
||||
InitQueue(QueueDefault, 1)
|
||||
InitQueue(QueueProcessing, int(math.Ceil(float64(runtime.NumCPU())/2.0)))
|
||||
InitQueue(QueueReports, 1)
|
||||
}
|
||||
|
||||
func InitQueue(name string, workers int) error {
|
||||
if _, ok := jobqueues[name]; ok {
|
||||
return fmt.Errorf("queue '%s' already existing", name)
|
||||
}
|
||||
logbuch.Info("creating job queue '%s' (%d workers)", name, workers)
|
||||
jobqueues[name] = artifex.NewDispatcher(workers, 4096)
|
||||
jobqueues[name].Start()
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user