Skip to content

Commit

Permalink
retry to send alert to plugin channel if it fails (#1530)
Browse files Browse the repository at this point in the history
  • Loading branch information
blotus committed May 17, 2022
1 parent c2b298c commit 39f7e38
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pkg/apiserver/controllers/v1/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,16 @@ func FormatAlerts(result []*ent.Alert) models.AddAlertsRequest {

func (c *Controller) sendAlertToPluginChannel(alert *models.Alert, profileID uint) {
if c.PluginChannel != nil {
select {
case c.PluginChannel <- csplugin.ProfileAlert{ProfileID: uint(profileID), Alert: alert}:
log.Debugf("alert sent to Plugin channel")
default:
log.Warningf("Cannot send alert to Plugin channel")
RETRY:
for try := 0; try < 3; try++ {
select {
case c.PluginChannel <- csplugin.ProfileAlert{ProfileID: uint(profileID), Alert: alert}:
log.Debugf("alert sent to Plugin channel")
break RETRY
default:
log.Warningf("Cannot send alert to Plugin channel (try: %d)", try)
time.Sleep(time.Millisecond * 50)
}
}
}
}
Expand Down

0 comments on commit 39f7e38

Please sign in to comment.