refactor: parallelize scheduler retrieval

In many cases, a user may only set a global scheduler, and as such we waste the initial call to get the app scheduler. Parallelizing the fetch increases the speed at which we can check for the scheduler.
This commit is contained in:
Jose Diaz-Gonzalez committed 2020-12-29 23:55:13 -05:00
1 parent 164c4eefa7
commit 44461e21df
1 file changed
+27 -9
+27 -9
View File
@@ -11,6 +11,7 @@ import (
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"sync"
"unicode" "unicode"
"github.com/ryanuber/columnize" "github.com/ryanuber/columnize"
@@ -64,17 +65,34 @@ func CommandUsage(helpHeader string, helpContent string) {
// GetAppScheduler fetches the scheduler for a given application // GetAppScheduler fetches the scheduler for a given application
func GetAppScheduler(appName string) string { func GetAppScheduler(appName string) string {
if appName == "--global" { appScheduler := ""
appName = "" globalScheduler := ""
}
b, _ := PlugnTriggerOutput("config-get", []string{appName, "DOKKU_SCHEDULER"}...) var wg sync.WaitGroup
value := strings.TrimSpace(string(b[:]))
if value != "" {
return value
}
return GetGlobalScheduler() if appName != "--global" {
wg.Add(1)
go func() {
defer wg.Done()
b, _ := PlugnTriggerOutput("config-get", []string{appName, "DOKKU_SCHEDULER"}...)
value := strings.TrimSpace(string(b[:]))
if value != "" {
appScheduler = value
}
}()
}
wg.Add(1)
go func() {
defer wg.Done()
globalScheduler = GetGlobalScheduler()
}()
wg.Wait()
if appScheduler == "" {
appScheduler = globalScheduler
}
return appScheduler
} }
// GetGlobalScheduler fetchs the global scheduler // GetGlobalScheduler fetchs the global scheduler