Update run.go

This commit is contained in:
Daniel Hougaard
2024-09-04 10:44:39 +04:00
parent 0826b40e2a
commit 91ebcca0fd
+10 -6
View File
@@ -316,13 +316,12 @@ func executeCommandWithWatchMode(commandFlag string, args []string, watchMode bo
var processMutex sync.Mutex var processMutex sync.Mutex
var beingTerminated = false var beingTerminated = false
var currentETag string var currentETag string
environmentVariables, err := fetchAndFormatSecretsForShell(request, projectConfigDir, secretOverriding, expandSecrets, token)
if err != nil { if err != nil {
util.HandleError(err, "Failed to fetch secrets") util.HandleError(err, "Failed to fetch secrets")
} }
runCommandWithWatcher := func() { runCommandWithWatcher := func(environmentVariables models.InjectableEnvironmentResult) {
currentETag = environmentVariables.ETag currentETag = environmentVariables.ETag
secretsFetchedAt := time.Now() secretsFetchedAt := time.Now()
if secretsFetchedAt.After(lastSecretsFetch) { if secretsFetchedAt.After(lastSecretsFetch) {
@@ -404,7 +403,12 @@ func executeCommandWithWatchMode(commandFlag string, args []string, watchMode bo
}() }()
} }
runCommandWithWatcher() initialEnvironmentVariables, err := fetchAndFormatSecretsForShell(request, projectConfigDir, secretOverriding, expandSecrets, token)
if err != nil {
util.HandleError(err, "Failed to fetch secrets")
}
runCommandWithWatcher(initialEnvironmentVariables)
// this is the only logic strictly related to watch mode, the rest is shared with non-watch mode // this is the only logic strictly related to watch mode, the rest is shared with non-watch mode
if watchMode { if watchMode {
@@ -424,14 +428,14 @@ func executeCommandWithWatchMode(commandFlag string, args []string, watchMode bo
<-recheckSecretsChannel <-recheckSecretsChannel
watchMutex.Lock() watchMutex.Lock()
environmentVariables, err = fetchAndFormatSecretsForShell(request, projectConfigDir, secretOverriding, expandSecrets, token) newEnvironmentVariables, err := fetchAndFormatSecretsForShell(request, projectConfigDir, secretOverriding, expandSecrets, token)
if err != nil { if err != nil {
log.Error().Err(err).Msg("[HOT RELOAD] Failed to fetch secrets") log.Error().Err(err).Msg("[HOT RELOAD] Failed to fetch secrets")
continue continue
} }
if environmentVariables.ETag != currentETag { if newEnvironmentVariables.ETag != currentETag {
runCommandWithWatcher() runCommandWithWatcher(newEnvironmentVariables)
} else { } else {
log.Debug().Msg("[HOT RELOAD] No changes detected in secrets, not reloading process") log.Debug().Msg("[HOT RELOAD] No changes detected in secrets, not reloading process")
} }