Skip to content

Commit ad86655

Browse files
committed
fix(notifications): reset retries for failing notifications
1 parent cf84a26 commit ad86655

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

backend/pkg/notification/queuing.go

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -736,19 +736,17 @@ func QueueWebhookNotifications(notificationsByUserID types.NotificationsPerUserI
736736
}
737737
if len(notifications) > 0 {
738738
// reset Retries
739-
if w.Retries > 5 && w.LastSent.Valid && w.LastSent.Time.Add(time.Hour).Before(time.Now()) {
740-
_, err = db.FrontendWriterDB.Exec(`UPDATE users_webhooks SET retries = 0 WHERE id = $1;`, w.ID)
741-
if err != nil {
742-
log.Error(err, "error updating users_webhooks table; setting retries to zero", 0)
743-
continue
744-
}
745-
} else if w.Retries > 5 && !w.LastSent.Valid {
746-
log.Warnf("webhook '%v' has more than 5 retries and does not have a valid last_sent timestamp", w.Url)
747-
continue
748-
}
749-
750739
if w.Retries >= 5 {
751-
// early return
740+
if !w.LastSent.Valid {
741+
log.Warnf("webhook '%v' has 5 retries and does not have a valid last_sent timestamp", w.Url)
742+
} else if w.LastSent.Time.Add(time.Hour).Before(time.Now()) {
743+
_, err = db.FrontendWriterDB.Exec(`UPDATE users_webhooks SET retries = 0 WHERE id = $1;`, w.ID)
744+
if err != nil {
745+
log.Error(err, "error updating users_webhooks table; setting retries to zero", 0)
746+
} else {
747+
log.Infof("webhook '%v' has 5 retries and has been reset", w.Url)
748+
}
749+
}
752750
continue
753751
}
754752
}
@@ -836,19 +834,17 @@ func QueueWebhookNotifications(notificationsByUserID types.NotificationsPerUserI
836834
w := dashboardWebhookMap[userID][dashboardId][dashboardGroupId]
837835

838836
// reset Retries
839-
if w.Retries > 5 && w.LastSent.Valid && w.LastSent.Time.Add(time.Hour).Before(time.Now()) {
840-
_, err = db.WriterDb.Exec(`UPDATE users_val_dashboards_groups SET webhook_retries = 0 WHERE id = $1 AND dashboard_id = $2;`, dashboardGroupId, dashboardId)
841-
if err != nil {
842-
log.Error(err, "error updating users_webhooks table; setting retries to zero", 0)
843-
continue
844-
}
845-
} else if w.Retries > 5 && !w.LastSent.Valid {
846-
log.Warnf("webhook '%v' for dashboard %d and group %d has more than 5 retries and does not have a valid last_sent timestamp", w.Url, dashboardId, dashboardGroupId)
847-
continue
848-
}
849-
850837
if w.Retries >= 5 {
851-
// early return
838+
if !w.LastSent.Valid {
839+
log.Warnf("webhook '%v' for dashboard %d and group %d has more than 5 retries and does not have a valid last_sent timestamp", w.Url, dashboardId, dashboardGroupId)
840+
} else if w.LastSent.Time.Add(time.Hour).Before(time.Now()) {
841+
_, err = db.WriterDb.Exec(`UPDATE users_val_dashboards_groups SET webhook_retries = 0 WHERE id = $1 AND dashboard_id = $2;`, dashboardGroupId, dashboardId)
842+
if err != nil {
843+
log.Error(err, "error updating users_webhooks table; setting retries to zero", 0)
844+
} else {
845+
log.Infof("webhook '%v' for dashboard %d and group %d has 5 retries and has been reset", w.Url, dashboardId, dashboardGroupId)
846+
}
847+
}
852848
continue
853849
}
854850

0 commit comments

Comments
 (0)