-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(wip): introduce job processing system
refactor: adapt report generation scheduling
- Loading branch information
Showing
7 changed files
with
203 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.