Skip to content

Commit

Permalink
feat: retry for sending events to Pagerduty
Browse files Browse the repository at this point in the history
  • Loading branch information
nomeaning777 committed Oct 20, 2023
1 parent 5a9c13a commit 38db2a6
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/PagerDuty/go-pagerduty"
)

const RETRY_COUNT = 6
const errorTouchPath = "/var/tmp/failure-systemd-failure-notification"

func main() {
Expand Down Expand Up @@ -56,8 +57,24 @@ func main() {
Details: details,
}
event.Payload = payload
if _, err := pagerduty.ManageEventWithContext(context.Background(), event); err != nil {
log.Printf("failed to send to pagerduty: %+v", err)

var retryErr error
retryWaitDuration := time.Second
for retryCount := 0; retryCount <= RETRY_COUNT; retryCount += 1 {
if retryCount > 0 {
time.Sleep(retryWaitDuration)
retryWaitDuration *= 2
}
if _, err := pagerduty.ManageEventWithContext(context.Background(), event); err != nil {
log.Printf("failed to send to pagerduty: %+v", err)
retryErr = err
} else {
retryErr = nil
break
}
}

if retryErr != nil {
f, err := os.Create(errorTouchPath)
if err != nil {
log.Printf("failed to touch error file: %+v", err)
Expand Down

0 comments on commit 38db2a6

Please sign in to comment.