refactor: collect process status in parallel
This speeds up ps:report for apps that have more than 1 running container.
This commit is contained in:
1 parent
28c9f42a25
commit
5da5a6fe5f
1 file changed
+17
-4
+17
-4
@@ -23,17 +23,30 @@ func ReportSingleApp(appName, infoFlag string) error {
|
|||||||
"--running": reportRunningState,
|
"--running": reportRunningState,
|
||||||
}
|
}
|
||||||
|
|
||||||
infoFlags := common.CollectReport(appName, flags)
|
|
||||||
scheduler := common.GetAppScheduler(appName)
|
scheduler := common.GetAppScheduler(appName)
|
||||||
if scheduler == "docker-local" {
|
if scheduler == "docker-local" {
|
||||||
processStatus := getProcessStatus(appName)
|
containerFiles := common.ListFilesWithPrefix(common.AppRoot(appName), "CONTAINER.")
|
||||||
for process, value := range processStatus {
|
for _, filename := range containerFiles {
|
||||||
infoFlags[fmt.Sprintf("--status-%s", process)] = value
|
// See https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables
|
||||||
|
containerFilePath := filename
|
||||||
|
process := strings.TrimPrefix(filename, fmt.Sprintf("%s/CONTAINER.", common.AppRoot(appName)))
|
||||||
|
|
||||||
|
flags[fmt.Sprintf("--status-%s", process)] = func(appName string) string {
|
||||||
|
containerID := common.ReadFirstLine(containerFilePath)
|
||||||
|
containerStatus, _ := common.DockerInspect(containerID, "{{ .State.Status }}")
|
||||||
|
|
||||||
|
if containerStatus == "" {
|
||||||
|
containerStatus = "missing"
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s (CID: %s)", containerStatus, containerID[0:11])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trimPrefix := false
|
trimPrefix := false
|
||||||
uppercaseFirstCharacter := true
|
uppercaseFirstCharacter := true
|
||||||
|
infoFlags := common.CollectReport(appName, flags)
|
||||||
return common.ReportSingleApp("ps", appName, infoFlag, infoFlags, trimPrefix, uppercaseFirstCharacter)
|
return common.ReportSingleApp("ps", appName, infoFlag, infoFlags, trimPrefix, uppercaseFirstCharacter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user