-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexecutor_registry.go
More file actions
44 lines (36 loc) · 931 Bytes
/
executor_registry.go
File metadata and controls
44 lines (36 loc) · 931 Bytes
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
37
38
39
40
41
42
43
44
package gds
import (
"github.com/integration-system/gds/jobs"
"sync"
)
type JobExecutor func(jobs.Job) error
type executorRegistry interface {
Register(jType string, executor JobExecutor)
Unregister(jType string)
GetExecutor(jType string) (JobExecutor, bool)
}
type defaultExecutorRegistry struct {
lock sync.RWMutex
registry map[string]JobExecutor
}
func (r *defaultExecutorRegistry) Register(jType string, executor JobExecutor) {
r.lock.Lock()
r.registry[jType] = executor
r.lock.Unlock()
}
func (r *defaultExecutorRegistry) Unregister(jType string) {
r.lock.Lock()
delete(r.registry, jType)
r.lock.Unlock()
}
func (r *defaultExecutorRegistry) GetExecutor(jType string) (JobExecutor, bool) {
r.lock.RLock()
e, ok := r.registry[jType]
r.lock.RUnlock()
return e, ok
}
func newDefaultExecutorRegistry() executorRegistry {
return &defaultExecutorRegistry{
registry: make(map[string]JobExecutor),
}
}