forked from taoh/gocelery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.go
36 lines (29 loc) · 782 Bytes
/
worker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package gocelery
import "sort"
// Worker is the definition of task execution
type Worker interface {
Execute(*Task) (interface{}, error)
}
var workerRegistery = make(map[string]Worker)
// Constants
const (
JSON string = "application/json"
)
// RegisterWorker registers the worker with given task name
func RegisterWorker(name string, worker Worker) {
workerRegistery[name] = worker
}
// RegisteredWorkers List all registered workers
func RegisteredWorkers() []string {
keys := make([]string, 0, len(workerRegistery))
for key := range workerRegistery {
keys = append(keys, key)
}
sort.Strings(keys)
return keys
}
// IsWorkerRegistered checks if worker exists for the task name
func IsWorkerRegistered(name string) bool {
_, ok := workerRegistery[name]
return ok
}