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 :)
This commit is contained in:
Jose Diaz-Gonzalez committed 2021-01-02 18:45:30 -05:00
1 parent aa0437bb23
commit 596e7b6f24
1 file changed
+25 -10
+25 -10
View File
@@ -112,23 +112,38 @@ func GetGlobalScheduler() string {
// GetDeployingAppImageName returns deploying image identifier for a given app, tag tuple. validate if tag is presented // GetDeployingAppImageName returns deploying image identifier for a given app, tag tuple. validate if tag is presented
func GetDeployingAppImageName(appName, imageTag, imageRepo string) (string, error) { func GetDeployingAppImageName(appName, imageTag, imageRepo string) (string, error) {
imageRemoteRepository := ""
newImageTag := ""
newImageRepo := ""
ctx := context.Background()
errs, ctx := errgroup.WithContext(ctx)
errs.Go(func() error {
b, err := PlugnTriggerOutput("deployed-app-repository", []string{appName}...) b, err := PlugnTriggerOutput("deployed-app-repository", []string{appName}...)
if err != nil { if err == nil {
return "", err imageRemoteRepository = strings.TrimSpace(string(b[:]))
} }
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-tag", []string{appName}...) errs.Go(func() error {
if err != nil { b, err := PlugnTriggerOutput("deployed-app-image-repo", []string{appName}...)
return "", err if err == nil {
newImageTag = strings.TrimSpace(string(b[:]))
} }
newImageTag := strings.TrimSpace(string(b[:])) return err
})
b, err = PlugnTriggerOutput("deployed-app-image-repo", []string{appName}...) if err := errs.Wait(); err != nil {
if err != nil {
return "", err return "", err
} }
newImageRepo := strings.TrimSpace(string(b[:]))
if newImageRepo != "" { if newImageRepo != "" {
imageRepo = newImageRepo imageRepo = newImageRepo