Skip to content

Commit

Permalink
Merge pull request #9 from ploperations/env_reset_delay
Browse files Browse the repository at this point in the history
Add an optional delay before an environment reset / retry
  • Loading branch information
suckatrash authored Jul 20, 2021
2 parents 0572485 + 385a84a commit 0ed9d9b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion puppet-runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func isValidEnvironment(environment string) bool {
func main() {
puppetEnv := flag.String("env", "production", "The Puppet environment to fall back to")
debugFlag := flag.Bool("debug", false, "Enable debugging information")
envResetDelay := flag.Int("env-reset-delay", 0, "Delay in minutes before reverting to fall back environment")

flag.Parse()
cliArgs := flag.Args()
Expand All @@ -150,7 +151,12 @@ func main() {
}

if environment == "" || !isValidEnvironment(environment) {
log.Printf("Environment %q is invalid; resetting", environment)
if *envResetDelay != 0 {
log.Printf("Environment %q is invalid, resetting in %d minutes", environment, *envResetDelay)
time.Sleep(time.Duration(*envResetDelay) * time.Minute)
} else {
log.Printf("Environment %q is invalid; resetting now", environment)
}
puppetConfigSet("agent", "environment", *puppetEnv)
}

Expand Down

0 comments on commit 0ed9d9b

Please sign in to comment.