Skip to content

Commit

Permalink
added workers and fixed delay
Browse files Browse the repository at this point in the history
  • Loading branch information
herlon214 committed Dec 14, 2021
1 parent 86813ec commit 68ddf12
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cmd/server/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ func Run(cmd *cobra.Command, args []string) {

// Process queue
queue := make(chan func() error, 0)
go ProcessQueue(queue)
for i := 0; i < workers; i++ {
go ProcessQueue(queue)
}

// Listen
http.HandleFunc("/webhook", WebhookHandler(webhookSecret, sonar, gh, queue))
Expand Down Expand Up @@ -143,7 +145,7 @@ func WebhookHandler(webhookSecret string, sonar *sonarqube2.Sonarqube, gh scm2.S
// if the request takes more than 10s Sonarqube shows the message 'Server Unreachable'
func ProcessQueue(queue <-chan func() error) {
for fn := range queue {
err := retry.Do(fn, retry.Delay(time.Minute), retry.Attempts(5))
err := retry.Do(fn, retry.Delay(time.Minute), retry.DelayType(retry.FixedDelay), retry.Attempts(5))
if err != nil {
logrus.WithError(err).Errorln("Failed to process webhook")

Expand Down
2 changes: 2 additions & 0 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

var serverPort int
var workers int

var ServerCmd = &cobra.Command{
Use: "server",
Expand All @@ -13,5 +14,6 @@ var ServerCmd = &cobra.Command{

func init() {
ServerCmd.PersistentFlags().IntVarP(&serverPort, "port", "p", 8080, "Server port")
ServerCmd.PersistentFlags().IntVarP(&workers, "workers", "w", 30, "Workers count")
ServerCmd.AddCommand(RunCmd)
}

0 comments on commit 68ddf12

Please sign in to comment.