Skip to content

Commit

Permalink
Force panic after 10 failed executions
Browse files Browse the repository at this point in the history
  • Loading branch information
TwiN committed May 15, 2020
1 parent 3e730cc commit 6883fbd
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ import (
"time"
)

const (
MaximumFailedExecutionBeforePanic = 10
)

var (
executionFailedCounter = 0
)

func main() {
err := config.Initialize()
if err != nil {
Expand All @@ -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)
Expand Down

0 comments on commit 6883fbd

Please sign in to comment.