1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

refactor(wip): introduce job processing system

refactor: adapt report generation scheduling
This commit is contained in:
Ferdinand Mütsch
2022-11-19 22:21:51 +01:00
parent b1a12a5759
commit e2ef54152d
7 changed files with 204 additions and 88 deletions

44
config/jobqueue.go Normal file
View File

@@ -0,0 +1,44 @@
package config
import (
"fmt"
"github.com/muety/artifex"
)
var jobqueues map[string]*artifex.Dispatcher
const (
QueueDefault = ""
QueueProcessing = "processing"
QueueMails = "mails"
)
func init() {
jobqueues = make(map[string]*artifex.Dispatcher)
}
func InitQueue(name string, workers int) error {
if _, ok := jobqueues[name]; ok {
return fmt.Errorf("queue '%s' already existing", name)
}
jobqueues[name] = artifex.NewDispatcher(workers, 4096)
jobqueues[name].Start()
return nil
}
func GetDefaultQueue() *artifex.Dispatcher {
return GetQueue("")
}
func GetQueue(name string) *artifex.Dispatcher {
if _, ok := jobqueues[name]; !ok {
InitQueue(name, 1)
}
return jobqueues[name]
}
func CloseQueues() {
for _, q := range jobqueues {
q.Stop()
}
}