Move event types constants into single file

Move all constants for event types to types.go for easier code
readability and maintainance.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
This commit is contained in:
Zhang Wei 2016-04-19 19:02:37 +08:00
parent 63001ee20d
commit e213e2eb62
8 changed files with 20 additions and 8 deletions

View file

@ -35,7 +35,7 @@ func (s *Supervisor) addProcess(t *AddProcessTask) error {
t.StartResponse <- StartResponse{} t.StartResponse <- StartResponse{}
s.notifySubscribers(Event{ s.notifySubscribers(Event{
Timestamp: time.Now(), Timestamp: time.Now(),
Type: "start-process", Type: StateStartProcess,
PID: t.PID, PID: t.PID,
ID: t.ID, ID: t.ID,
}) })

View file

@ -23,7 +23,7 @@ func (s *Supervisor) delete(t *DeleteTask) error {
} }
if !t.NoEvent { if !t.NoEvent {
s.notifySubscribers(Event{ s.notifySubscribers(Event{
Type: "exit", Type: StateExit,
Timestamp: time.Now(), Timestamp: time.Now(),
ID: t.ID, ID: t.ID,
Status: t.Status, Status: t.Status,

View file

@ -73,7 +73,7 @@ func (s *Supervisor) execExit(t *ExecExitTask) error {
s.notifySubscribers(Event{ s.notifySubscribers(Event{
Timestamp: time.Now(), Timestamp: time.Now(),
ID: t.ID, ID: t.ID,
Type: "exit", Type: StateExit,
PID: t.PID, PID: t.PID,
Status: t.Status, Status: t.Status,
}) })

View file

@ -16,7 +16,7 @@ func (s *Supervisor) oom(t *OOMTask) error {
s.notifySubscribers(Event{ s.notifySubscribers(Event{
Timestamp: time.Now(), Timestamp: time.Now(),
ID: t.ID, ID: t.ID,
Type: "oom", Type: StateOOM,
}) })
return nil return nil
} }

View file

@ -161,7 +161,7 @@ func (s *Supervisor) Events(from time.Time) chan Event {
} }
// Notify the client that from now on it's live events // Notify the client that from now on it's live events
c <- Event{ c <- Event{
Type: "live", Type: StateLive,
Timestamp: time.Now(), Timestamp: time.Now(),
} }
} }

12
supervisor/types.go Normal file
View file

@ -0,0 +1,12 @@
package supervisor
// State constants used in Event types
const (
StateStart = "start-container"
StatePause = "pause"
StateResume = "resume"
StateExit = "exit"
StateStartProcess = "start-process"
StateOOM = "oom"
StateLive = "live"
)

View file

@ -27,7 +27,7 @@ func (s *Supervisor) updateContainer(t *UpdateTask) error {
} }
s.notifySubscribers(Event{ s.notifySubscribers(Event{
ID: t.ID, ID: t.ID,
Type: "resume", Type: StateResume,
Timestamp: time.Now(), Timestamp: time.Now(),
}) })
case runtime.Paused: case runtime.Paused:
@ -36,7 +36,7 @@ func (s *Supervisor) updateContainer(t *UpdateTask) error {
} }
s.notifySubscribers(Event{ s.notifySubscribers(Event{
ID: t.ID, ID: t.ID,
Type: "pause", Type: StatePause,
Timestamp: time.Now(), Timestamp: time.Now(),
}) })
default: default:

View file

@ -68,7 +68,7 @@ func (w *worker) Start() {
w.s.notifySubscribers(Event{ w.s.notifySubscribers(Event{
Timestamp: time.Now(), Timestamp: time.Now(),
ID: t.Container.ID(), ID: t.Container.ID(),
Type: "start-container", Type: StateStart,
}) })
} }
} }