-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_manager.go
59 lines (51 loc) · 1.28 KB
/
job_manager.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package dockworker
import (
log "github.com/Sirupsen/logrus"
"github.com/fsouza/go-dockerclient"
)
// JobManager manages Jobs
type JobManager interface {
NotifyNewJob(job Job)
Start()
Stop()
}
// NewJobManager returns a new JobManager
func NewJobManager(jobStore JobStore, client *docker.Client, eventListner DockerEventListener, jobUpdater JobUpdater, stopEventListener StopEventListener) JobManager {
return jobManager{
jobStore: jobStore,
client: client,
newJobs: make(chan Job, 100),
eventListner: eventListner,
jobUpdater: jobUpdater,
stopEventListener: stopEventListener,
}
}
type jobManager struct {
jobStore JobStore
client *docker.Client
newJobs chan Job
stopEventListener StopEventListener
eventListner DockerEventListener
jobUpdater JobUpdater
}
func (jm jobManager) Start() {
log.Info("Job manager starting up...")
go jm.manager()
}
func (jm jobManager) Stop() {
// TODO: implement
}
func (jm jobManager) NotifyNewJob(job Job) {
log.Debugf("Notifying new job %d", job.ID)
jm.newJobs <- job
}
func (jm jobManager) manager() {
for {
select {
case job := <-jm.newJobs:
// start new job worker
log.Debugf("Starting new job %d", job.ID)
go jm.jobWorker(job)
}
}
}