Skip to content

Commit 0ed9d9b

Browse files
authored
Merge pull request #9 from ploperations/env_reset_delay
Add an optional delay before an environment reset / retry
2 parents 0572485 + 385a84a commit 0ed9d9b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

puppet-runner.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func isValidEnvironment(environment string) bool {
135135
func main() {
136136
puppetEnv := flag.String("env", "production", "The Puppet environment to fall back to")
137137
debugFlag := flag.Bool("debug", false, "Enable debugging information")
138+
envResetDelay := flag.Int("env-reset-delay", 0, "Delay in minutes before reverting to fall back environment")
138139

139140
flag.Parse()
140141
cliArgs := flag.Args()
@@ -150,7 +151,12 @@ func main() {
150151
}
151152

152153
if environment == "" || !isValidEnvironment(environment) {
153-
log.Printf("Environment %q is invalid; resetting", environment)
154+
if *envResetDelay != 0 {
155+
log.Printf("Environment %q is invalid, resetting in %d minutes", environment, *envResetDelay)
156+
time.Sleep(time.Duration(*envResetDelay) * time.Minute)
157+
} else {
158+
log.Printf("Environment %q is invalid; resetting now", environment)
159+
}
154160
puppetConfigSet("agent", "environment", *puppetEnv)
155161
}
156162

0 commit comments

Comments
 (0)