From 3bbeb8dbab8ce5a165dbe59e76fce4c11b3b4f83 Mon Sep 17 00:00:00 2001 From: Herlon Aguiar Date: Mon, 13 Dec 2021 18:33:13 +0100 Subject: [PATCH] cmd/server: added retry with fixed delay (#1) --- cmd/server/run.go | 15 +++++++++------ go.mod | 3 ++- go.sum | 2 ++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cmd/server/run.go b/cmd/server/run.go index 493405a..5135324 100644 --- a/cmd/server/run.go +++ b/cmd/server/run.go @@ -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{ @@ -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) diff --git a/go.mod b/go.mod index cbd2637..5d90f4b 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 3c33126..c7ec3b3 100644 --- a/go.sum +++ b/go.sum @@ -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=