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:
		| @@ -35,7 +35,7 @@ func (s *Supervisor) addProcess(t *AddProcessTask) error { | ||||
| 	t.StartResponse <- StartResponse{} | ||||
| 	s.notifySubscribers(Event{ | ||||
| 		Timestamp: time.Now(), | ||||
| 		Type:      "start-process", | ||||
| 		Type:      StateStartProcess, | ||||
| 		PID:       t.PID, | ||||
| 		ID:        t.ID, | ||||
| 	}) | ||||
|   | ||||
| @@ -23,7 +23,7 @@ func (s *Supervisor) delete(t *DeleteTask) error { | ||||
| 		} | ||||
| 		if !t.NoEvent { | ||||
| 			s.notifySubscribers(Event{ | ||||
| 				Type:      "exit", | ||||
| 				Type:      StateExit, | ||||
| 				Timestamp: time.Now(), | ||||
| 				ID:        t.ID, | ||||
| 				Status:    t.Status, | ||||
|   | ||||
| @@ -73,7 +73,7 @@ func (s *Supervisor) execExit(t *ExecExitTask) error { | ||||
| 	s.notifySubscribers(Event{ | ||||
| 		Timestamp: time.Now(), | ||||
| 		ID:        t.ID, | ||||
| 		Type:      "exit", | ||||
| 		Type:      StateExit, | ||||
| 		PID:       t.PID, | ||||
| 		Status:    t.Status, | ||||
| 	}) | ||||
|   | ||||
| @@ -16,7 +16,7 @@ func (s *Supervisor) oom(t *OOMTask) error { | ||||
| 	s.notifySubscribers(Event{ | ||||
| 		Timestamp: time.Now(), | ||||
| 		ID:        t.ID, | ||||
| 		Type:      "oom", | ||||
| 		Type:      StateOOM, | ||||
| 	}) | ||||
| 	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 | ||||
| 		c <- Event{ | ||||
| 			Type:      "live", | ||||
| 			Type:      StateLive, | ||||
| 			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{ | ||||
| 				ID:        t.ID, | ||||
| 				Type:      "resume", | ||||
| 				Type:      StateResume, | ||||
| 				Timestamp: time.Now(), | ||||
| 			}) | ||||
| 		case runtime.Paused: | ||||
| @@ -36,7 +36,7 @@ func (s *Supervisor) updateContainer(t *UpdateTask) error { | ||||
| 			} | ||||
| 			s.notifySubscribers(Event{ | ||||
| 				ID:        t.ID, | ||||
| 				Type:      "pause", | ||||
| 				Type:      StatePause, | ||||
| 				Timestamp: time.Now(), | ||||
| 			}) | ||||
| 		default: | ||||
|   | ||||
| @@ -68,7 +68,7 @@ func (w *worker) Start() { | ||||
| 		w.s.notifySubscribers(Event{ | ||||
| 			Timestamp: time.Now(), | ||||
| 			ID:        t.Container.ID(), | ||||
| 			Type:      "start-container", | ||||
| 			Type:      StateStart, | ||||
| 		}) | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Zhang Wei
					Zhang Wei