From 1f251d8257e2ffa44bbdbf7fe1a757bab8227f29 Mon Sep 17 00:00:00 2001 From: agourdel Date: Thu, 4 Jul 2024 16:18:06 +0200 Subject: [PATCH] Add maxRetry limit in handleNextRetry --- .../components/webhook_collector/collector.go | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/ee/webhooks/internal/components/webhook_collector/collector.go b/ee/webhooks/internal/components/webhook_collector/collector.go index 5d2d056e11..28ee15ea66 100644 --- a/ee/webhooks/internal/components/webhook_collector/collector.go +++ b/ee/webhooks/internal/components/webhook_collector/collector.go @@ -116,17 +116,29 @@ func (c *Collector) handleSuccess(sAttempt *commons.SharedAttempt) { func (c *Collector) handleNextRetry(sAttempt *commons.SharedAttempt) { sAttempt.Val.NbTry += 1 - commons.SetNextRetry(sAttempt.Val) - c.State.WaitingAttempts.Add(sAttempt) - go func() { - _, err := c.Database.UpdateAttemptNextTry(sAttempt.Val.ID, sAttempt.Val.NextTry, sAttempt.Val.LastHttpStatusCode) + if(c.RunnerParams.MaxRetry <= sAttempt.Val.NbTry ) { + commons.SetAbortMaxRetryStatus(sAttempt.Val) + _, err := c.Database.AbortAttempt(sAttempt.Val.ID, string(sAttempt.Val.Comment), false) if err != nil { - message := fmt.Sprintf("Collector:handleNextRetry:Database.UpdateAttemptNextTry: %x", err) + message := fmt.Sprintf("Collector:handleNextRetry:Database.AbortAttempt: %x", err) logging.Error(message) panic(message) } - }() + }else { + + commons.SetNextRetry(sAttempt.Val) + c.State.WaitingAttempts.Add(sAttempt) + + go func() { + _, err := c.Database.UpdateAttemptNextTry(sAttempt.Val.ID, sAttempt.Val.NextTry, sAttempt.Val.LastHttpStatusCode) + if err != nil { + message := fmt.Sprintf("Collector:handleNextRetry:Database.UpdateAttemptNextTry: %x", err) + logging.Error(message) + panic(message) + } + }() + } } func (c *Collector) handleMissingHook(sAttempt *commons.SharedAttempt) {