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
2020-12-29 23:55:13 -05:00
parent 164c4eefa7
commit 44461e21df

View File

@@ -11,6 +11,7 @@ import (
"sort"
"strconv"
"strings"
"sync"
"unicode"
"github.com/ryanuber/columnize"
@@ -64,17 +65,34 @@ func CommandUsage(helpHeader string, helpContent string) {
// GetAppScheduler fetches the scheduler for a given application
func GetAppScheduler(appName string) string {
if appName == "--global" {
appName = ""
}
appScheduler := ""
globalScheduler := ""
b, _ := PlugnTriggerOutput("config-get", []string{appName, "DOKKU_SCHEDULER"}...)
value := strings.TrimSpace(string(b[:]))
if value != "" {
return value
}
var wg sync.WaitGroup
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