Skip to content

Commit

Permalink
cmd/server: added retry with fixed delay (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
herlon214 authored Dec 13, 2021
1 parent 91d4c92 commit 3bbeb8d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
15 changes: 9 additions & 6 deletions cmd/server/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/avast/retry-go"
scm2 "github.com/herlon214/sonarqube-pr-issues/pkg/scm"
sonarqube2 "github.com/herlon214/sonarqube-pr-issues/pkg/sonarqube"
"io"
"net/http"
"os"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"io"
"net/http"
"os"
"time"
)

var RunCmd = &cobra.Command{
Expand Down Expand Up @@ -118,8 +119,10 @@ func WebhookHandler(webhookSecret string, sonar *sonarqube2.Sonarqube, gh scm2.S

logrus.Infoln("Processing", webhook.Project.Key, "->", webhook.Branch.Name)

// Process the event
err = PublishIssues(req.Context(), sonar, gh, webhook.Project.Key, webhook.Branch.Name)
// Process the event with retry
err = retry.Do(func() error {
return PublishIssues(req.Context(), sonar, gh, webhook.Project.Key, webhook.Branch.Name)
}, retry.Delay(time.Minute), retry.Attempts(5))
if err != nil {
logrus.WithError(err).Errorln("Failed to publish issues for", webhook.Project.Key, webhook.Branch.Name)

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ module github.com/herlon214/sonarqube-pr-issues
go 1.17

require (
github.com/avast/retry-go v2.7.0+incompatible
github.com/google/go-github/v41 v41.0.0
github.com/migueleliasweb/go-github-mock v0.0.5
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
Expand All @@ -18,7 +20,6 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/migueleliasweb/go-github-mock v0.0.5
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kd
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/avast/retry-go v2.7.0+incompatible h1:XaGnzl7gESAideSjr+I8Hki/JBi+Yb9baHlMRPeSC84=
github.com/avast/retry-go v2.7.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
Expand Down

0 comments on commit 3bbeb8d

Please sign in to comment.