forked from coreos/fleet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.go
50 lines (39 loc) · 1.42 KB
/
event.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
package engine
import (
log "github.com/golang/glog"
"github.com/coreos/fleet/event"
"github.com/coreos/fleet/job"
)
type EventHandler struct {
engine *Engine
}
func NewEventHandler(engine *Engine) *EventHandler {
return &EventHandler{engine}
}
func (self *EventHandler) HandleEventJobCreated(ev event.Event) {
j := ev.Payload.(job.Job)
log.V(1).Infof("EventJobCreated(%s): publishing JobOffer", j.Name)
self.engine.OfferJob(j)
}
func (self *EventHandler) HandleEventJobBidSubmitted(ev event.Event) {
jb := ev.Payload.(job.JobBid)
log.V(1).Infof("EventJobBidSubmitted(%s): attempting to schedule Job to Machine(%s)", jb.JobName, jb.MachineName)
err := self.engine.ResolveJobOffer(jb.JobName, jb.MachineName)
if err == nil {
log.V(1).Infof("EventJobBidSubmitted(%s): successfully scheduled Job to Machine(%s)", jb.JobName, jb.MachineName)
} else {
log.V(1).Infof("EventJobBidSubmitted(%s): failed to schedule Job to Machine(%s): %s", jb.JobName, jb.MachineName, err.Error())
}
}
func (self *EventHandler) HandleEventMachineRemoved(ev event.Event) {
machName := ev.Payload.(string)
jobs := self.engine.GetJobsScheduledToMachine(machName)
for _, j := range jobs {
log.V(1).Infof("EventMachineRemoved(%s): stopping Job(%s)", machName, j.Name)
self.engine.UnscheduleJob(j.Name)
}
for _, j := range jobs {
log.V(1).Infof("EventMachineRemoved(%s): re-publishing JobOffer(%s)", machName, j.Name)
self.engine.OfferJob(j)
}
}