From 596e7b6f24a0c36d7614f673c4eeb610f2af3739 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 1 Jan 2021 21:14:33 -0500 Subject: [PATCH] feat: use error group to fetch the deploying app image This is a fairly slow operation currently done serially, making ps:scale output brutally slow. Using an error group to parallelize the output is also pleasing to the eyes :) --- plugins/common/common.go | 41 +++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/plugins/common/common.go b/plugins/common/common.go index be4b38c7a..9c4e8d6de 100644 --- a/plugins/common/common.go +++ b/plugins/common/common.go @@ -112,23 +112,38 @@ func GetGlobalScheduler() string { // GetDeployingAppImageName returns deploying image identifier for a given app, tag tuple. validate if tag is presented func GetDeployingAppImageName(appName, imageTag, imageRepo string) (string, error) { - b, err := PlugnTriggerOutput("deployed-app-repository", []string{appName}...) - if err != nil { - return "", err - } - imageRemoteRepository := strings.TrimSpace(string(b[:])) + imageRemoteRepository := "" + newImageTag := "" + newImageRepo := "" - b, err = PlugnTriggerOutput("deployed-app-image-tag", []string{appName}...) - if err != nil { - return "", err - } - newImageTag := strings.TrimSpace(string(b[:])) + ctx := context.Background() + errs, ctx := errgroup.WithContext(ctx) + errs.Go(func() error { + b, err := PlugnTriggerOutput("deployed-app-repository", []string{appName}...) + if err == nil { + imageRemoteRepository = strings.TrimSpace(string(b[:])) + } + return err + }) + errs.Go(func() error { + b, err := PlugnTriggerOutput("deployed-app-image-tag", []string{appName}...) + if err == nil { + newImageTag = strings.TrimSpace(string(b[:])) + } + return err + }) - b, err = PlugnTriggerOutput("deployed-app-image-repo", []string{appName}...) - if err != nil { + errs.Go(func() error { + b, err := PlugnTriggerOutput("deployed-app-image-repo", []string{appName}...) + if err == nil { + newImageTag = strings.TrimSpace(string(b[:])) + } + return err + }) + + if err := errs.Wait(); err != nil { return "", err } - newImageRepo := strings.TrimSpace(string(b[:])) if newImageRepo != "" { imageRepo = newImageRepo