reid 2 tahun lalu
induk
melakukan
4260d0e4d1
3 mengubah file dengan 22 tambahan dan 11 penghapusan
  1. 2 0
      config/config.go
  2. 14 6
      rectify/rectify.go
  3. 6 5
      structs/structs.go

+ 2 - 0
config/config.go

@@ -121,6 +121,8 @@ func UpdateContainerState(name string, containerState structs.ContainerState) {
 	contMutex.Lock()
 	defer contMutex.Unlock()
 	GSContainers[name] = containerState
+	res, _ := json.Marshal(containerState)
+	logger.Info(fmt.Sprintf("%s:%s", name, string(res)))
 }
 
 // get the current container state

+ 14 - 6
rectify/rectify.go

@@ -33,17 +33,25 @@ func DockerSubscriptionHandler() {
 		case "stop":
 			logger.Info(fmt.Sprintf("Docker: %s stopped", contName))
 
-			if containerState, exists := config.GSContainers[contID]; exists {
-				containerState.Status = "stopped"
-				config.GSContainers[contID] = containerState
+			if containerState, exists := config.GetContainerState()[contName]; exists {
+				containerState.ActualStatus = "stopped"
+				config.UpdateContainerState(contName, containerState)
 			}
 
 		case "start":
 			logger.Info(fmt.Sprintf("Docker: %s started", contName))
 
-			if containerState, exists := config.GSContainers[contID]; exists {
-				containerState.Status = "started"
-				config.GSContainers[contID] = containerState
+			if containerState, exists := config.GetContainerState()[contName]; exists {
+				containerState.ActualStatus = "started"
+				config.UpdateContainerState(contName, containerState)
+			}
+
+		case "die":
+			logger.Info(fmt.Sprintf("Docker: %s died!", contName))
+			if containerState, exists := config.GetContainerState()[contName]; exists {
+				containerState.ActualStatus = "died"
+				containerState.DesiredStatus = "died"
+				config.UpdateContainerState(contName, containerState)
 			}
 
 		default:

+ 6 - 5
structs/structs.go

@@ -18,11 +18,12 @@ type Event struct {
 
 // for keeping track of container desired/actual state
 type ContainerState struct {
-	ID        string
-	Name      string
-	Image     string
-	Status    string
-	CreatedAt string
+	ID            string
+	Name          string
+	Image         string
+	ActualStatus  string
+	DesiredStatus string
+	CreatedAt     string
 }
 
 // authenticated browser sessions