From fc82335cbdcd24a020e49d11f2c91c714cacc889 Mon Sep 17 00:00:00 2001 From: in-void Date: Thu, 9 Mar 2023 18:18:20 +0100 Subject: [PATCH] retry on failure push (fcm) calls --- .../browser_extension/app/command/request_2fa_token.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/api/browser_extension/app/command/request_2fa_token.go b/internal/api/browser_extension/app/command/request_2fa_token.go index 858ca75..4f09d6b 100644 --- a/internal/api/browser_extension/app/command/request_2fa_token.go +++ b/internal/api/browser_extension/app/command/request_2fa_token.go @@ -4,6 +4,7 @@ import ( "context" "firebase.google.com/go/v4/messaging" "fmt" + "github.com/avast/retry-go/v4" "github.com/gin-gonic/gin" "github.com/google/uuid" "github.com/twofas/2fas-server/internal/api/browser_extension/domain" @@ -94,7 +95,12 @@ func (h *Request2FaTokenHandler) Handle(cmd *Request2FaToken) error { notification = createPushNotificationForIos(device.FcmToken, data) } - err = h.Pusher.Send(context.Background(), notification) + err = retry.Do( + func() error { + return h.Pusher.Send(context.Background(), notification) + }, + retry.Attempts(5), + ) if err != nil && !messaging.IsRegistrationTokenNotRegistered(err) { logging.WithFields(logging.Fields{