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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user