From 6883fbd3cbe4f28e019e48914a0e9588b96ae08d Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Fri, 15 May 2020 12:57:44 -0400 Subject: [PATCH] Force panic after 10 failed executions --- main.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.go b/main.go index 01d48892..9dc8142c 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,14 @@ import ( "time" ) +const ( + MaximumFailedExecutionBeforePanic = 10 +) + +var ( + executionFailedCounter = 0 +) + func main() { err := config.Initialize() if err != nil { @@ -28,6 +36,13 @@ func main() { for { if err := run(ec2Service, autoScalingService); err != nil { log.Printf("Error during execution: %s", err.Error()) + executionFailedCounter++ + if executionFailedCounter > MaximumFailedExecutionBeforePanic { + panic(fmt.Errorf("execution failed %d times: %v", executionFailedCounter, err)) + } + } else if executionFailedCounter > 0 { + log.Printf("Execution was successful after %d failed attempts, resetting counter to 0", executionFailedCounter) + executionFailedCounter = 0 } log.Println("Sleeping for 20 seconds") time.Sleep(20 * time.Second)