refactor: only add status flags as necessary
This commit is contained in:
1 parent
0e320d2832
commit
0176e888af
1 file changed
+36
-19
+36
-19
@@ -23,25 +23,9 @@ func ReportSingleApp(appName, infoFlag string) error {
|
|||||||
"--running": reportRunningState,
|
"--running": reportRunningState,
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduler := common.GetAppScheduler(appName)
|
extraFlags := addStatusFlags(appName, infoFlag)
|
||||||
if scheduler == "docker-local" {
|
for flag, fn := range extraFlags {
|
||||||
containerFiles := common.ListFilesWithPrefix(common.AppRoot(appName), "CONTAINER.")
|
flags[flag] = fn
|
||||||
for _, filename := range containerFiles {
|
|
||||||
// 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
|
||||||
@@ -50,6 +34,39 @@ func ReportSingleApp(appName, infoFlag string) error {
|
|||||||
return common.ReportSingleApp("ps", appName, infoFlag, infoFlags, trimPrefix, uppercaseFirstCharacter)
|
return common.ReportSingleApp("ps", appName, infoFlag, infoFlags, trimPrefix, uppercaseFirstCharacter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addStatusFlags(appName string, infoFlag string) map[string]common.ReportFunc {
|
||||||
|
flags := map[string]common.ReportFunc{}
|
||||||
|
|
||||||
|
if infoFlag != "" && !strings.HasPrefix(infoFlag, "--status-") {
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
|
scheduler := common.GetAppScheduler(appName)
|
||||||
|
if scheduler != "docker-local" {
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
|
containerFiles := common.ListFilesWithPrefix(common.AppRoot(appName), "CONTAINER.")
|
||||||
|
for _, filename := range containerFiles {
|
||||||
|
// 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])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
func reportCanScale(appName string) string {
|
func reportCanScale(appName string) string {
|
||||||
canScale := "false"
|
canScale := "false"
|
||||||
if canScaleApp(appName) {
|
if canScaleApp(appName) {
|
||||||
|
|||||||
Reference in new issue
Block a user