From 4bb343769f40481736a68eacfae6f3acc5edf522 Mon Sep 17 00:00:00 2001 From: Paulo Truta Date: Wed, 17 Apr 2024 20:40:00 +0200 Subject: [PATCH] Faster GetEdgeAppServices by skipping ones that should not be running --- internal/edgeapps/edgeapps.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/internal/edgeapps/edgeapps.go b/internal/edgeapps/edgeapps.go index f07b20c..9ba4605 100644 --- a/internal/edgeapps/edgeapps.go +++ b/internal/edgeapps/edgeapps.go @@ -416,12 +416,24 @@ func GetEdgeAppServices(ID string) []EdgeAppService { var edgeAppServices []EdgeAppService for _, serviceID := range serviceSlices { - cmdArgs = []string{"-f", wsPath + "/docker-compose.yml", "exec", "-T", serviceID, "echo", "'Service Check'"} - cmdResult := utils.Exec(wsPath, "docker-compose", cmdArgs) + shouldBeRunning := false isRunning := false - if cmdResult != "" { - isRunning = true + + // Check if the service is marked as "runnable" with the .run lockfile in the app folder + _, err := os.Stat(utils.GetPath(utils.EdgeAppsPath) + ID + "/" + serviceID + runnableFilename) + if !os.IsNotExist(err) { + shouldBeRunning = true } + + // Check if the service is actually running + if shouldBeRunning { + cmdArgs = []string{"-f", wsPath + "/docker-compose.yml", "exec", "-T", serviceID, "echo", "'Service Check'"} + cmdResult := utils.Exec(wsPath, "docker-compose", cmdArgs) + if cmdResult != "" { + isRunning = true + } + } + edgeAppServices = append(edgeAppServices, EdgeAppService{ID: serviceID, IsRunning: isRunning}) }