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
2021-01-01 21:14:33 -05:00
parent aa0437bb23
commit 596e7b6f24

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
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