log.Errorf("could not send notification '%s' to notifier '%s': %s",notification.GetName(),notifierName,err)
varattemptsint
varbackOfftime.Duration
for{
// Max attempts exceeded.
ifattempts>=maxAttempts{
log.Infof("giving up on sending notification '%s' to notifier '%s': max attempts exceeded (%d)\n",notification.GetName(),notifierName,maxAttempts)
returnfalse
}
// Backoff.
ifbackOff>0{
log.Infof("waiting %v before retrying to send notification '%s' to notifier '%s' (Attempt %d / %d)\n",backOff,notification.GetName(),notifierName,attempts+1,maxAttempts)
if!st.Sleep(backOff){
returnfalse
}
}
// Send using the current notifier.
iferr:=notifier.Send(payload);err==nil{
// Send has been successful. Go to the next one.
break
}
// Send failed; increase attempts/backoff and retry.
log.Errorf("could not send notification '%s' to notifier '%s': %s",notification.GetName(),notifierName,err)
backOff=timeutil.ExpBackoff(backOff,maxBackOff)
attempts++
}
}
log.Infof("successfully sent notification '%s'\n",notification.GetName())