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:
parent
63001ee20d
commit
e213e2eb62
8 changed files with 20 additions and 8 deletions
|
@ -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,
|
||||||
})
|
})
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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,
|
||||||
})
|
})
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
12
supervisor/types.go
Normal 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"
|
||||||
|
)
|
|
@ -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:
|
||||||
|
|
|
@ -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,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue