From 6d65c1ea6ec707f313a409321f3f7d4be365b160 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 2 Aug 2021 12:37:38 +0800 Subject: [PATCH] chore(push): send error to specific URL (#621) Signed-off-by: Bo-Yi Wu --- notify/notification.go | 9 ++++++++ notify/notification_apns.go | 16 +------------ notify/notification_fcm.go | 46 ++++--------------------------------- notify/notification_hms.go | 4 ---- 4 files changed, 15 insertions(+), 60 deletions(-) diff --git a/notify/notification.go b/notify/notification.go index f2eeb66..e299a30 100644 --- a/notify/notification.go +++ b/notify/notification.go @@ -250,6 +250,15 @@ func SendNotification(req queue.QueuedMessage, cfg config.ConfYaml) (resp *Respo resp, err = PushToHuawei(*v, cfg) } + if cfg.Core.FeedbackURL != "" { + for _, l := range resp.Logs { + err := DispatchFeedback(l, cfg.Core.FeedbackURL, cfg.Core.FeedbackTimeout) + if err != nil { + logx.LogError.Error(err) + } + } + } + return } diff --git a/notify/notification_apns.go b/notify/notification_apns.go index e434c51..058e351 100644 --- a/notify/notification_apns.go +++ b/notify/notification_apns.go @@ -21,7 +21,6 @@ import ( "github.com/sideshow/apns2/certificate" "github.com/sideshow/apns2/payload" "github.com/sideshow/apns2/token" - "github.com/sirupsen/logrus" "golang.org/x/net/http2" ) @@ -391,10 +390,6 @@ func getApnsClient(cfg config.ConfYaml, req PushNotification) (client *apns2.Cli func PushToIOS(req PushNotification, cfg config.ConfYaml) (resp *ResponsePush, err error) { logx.LogAccess.Debug("Start push notification for iOS") - if cfg.Core.Sync && !core.IsLocalQueue(core.Queue(cfg.Queue.Engine)) { - cfg.Core.Sync = false - } - var ( retryCount = 0 maxRetry = cfg.Ios.MaxRetry @@ -431,16 +426,7 @@ Retry: // apns server error errLog := logPush(cfg, core.FailedPush, token, req, err) - if cfg.Core.Sync { - resp.Logs = append(resp.Logs, errLog) - } else if cfg.Core.FeedbackURL != "" { - go func(logger *logrus.Logger, log logx.LogPushEntry, url string, timeout int64) { - err := DispatchFeedback(log, url, timeout) - if err != nil { - logger.Error(err) - } - }(logx.LogError, errLog, cfg.Core.FeedbackURL, cfg.Core.FeedbackTimeout) - } + resp.Logs = append(resp.Logs, errLog) status.StatStorage.AddIosError(1) // We should retry only "retryable" statuses. More info about response: diff --git a/notify/notification_fcm.go b/notify/notification_fcm.go index 2401b13..bd5e8ce 100644 --- a/notify/notification_fcm.go +++ b/notify/notification_fcm.go @@ -10,7 +10,6 @@ import ( "github.com/appleboy/gorush/status" "github.com/appleboy/go-fcm" - "github.com/sirupsen/logrus" ) // InitFCMClient use for initialize FCM Client. @@ -109,10 +108,6 @@ func GetAndroidNotification(req PushNotification) *fcm.Message { func PushToAndroid(req PushNotification, cfg config.ConfYaml) (resp *ResponsePush, err error) { logx.LogAccess.Debug("Start push notification for Android") - if cfg.Core.Sync && !core.IsLocalQueue(core.Queue(cfg.Queue.Engine)) { - cfg.Core.Sync = false - } - var ( client *fcm.Client retryCount = 0 @@ -154,30 +149,12 @@ Retry: if req.IsTopic() { errLog := logPush(cfg, core.FailedPush, req.To, req, err) - if cfg.Core.Sync { - resp.Logs = append(resp.Logs, errLog) - } else if cfg.Core.FeedbackURL != "" { - go func(logger *logrus.Logger, log logx.LogPushEntry, url string, timeout int64) { - err := DispatchFeedback(log, url, timeout) - if err != nil { - logger.Error(err) - } - }(logx.LogError, errLog, cfg.Core.FeedbackURL, cfg.Core.FeedbackTimeout) - } + resp.Logs = append(resp.Logs, errLog) status.StatStorage.AddAndroidError(1) } else { for _, token := range req.Tokens { errLog := logPush(cfg, core.FailedPush, token, req, err) - if cfg.Core.Sync { - resp.Logs = append(resp.Logs, errLog) - } else if cfg.Core.FeedbackURL != "" { - go func(logger *logrus.Logger, log logx.LogPushEntry, url string, timeout int64) { - err := DispatchFeedback(log, url, timeout) - if err != nil { - logger.Error(err) - } - }(logx.LogError, errLog, cfg.Core.FeedbackURL, cfg.Core.FeedbackTimeout) - } + resp.Logs = append(resp.Logs, errLog) } status.StatStorage.AddAndroidError(int64(len(req.Tokens))) } @@ -209,16 +186,7 @@ Retry: } errLog := logPush(cfg, core.FailedPush, to, req, result.Error) - if cfg.Core.Sync { - resp.Logs = append(resp.Logs, errLog) - } else if cfg.Core.FeedbackURL != "" { - go func(logger *logrus.Logger, log logx.LogPushEntry, url string, timeout int64) { - err := DispatchFeedback(log, url, timeout) - if err != nil { - logger.Error(err) - } - }(logx.LogError, errLog, cfg.Core.FeedbackURL, cfg.Core.FeedbackTimeout) - } + resp.Logs = append(resp.Logs, errLog) continue } @@ -240,9 +208,7 @@ Retry: } else { // failure errLog := logPush(cfg, core.FailedPush, to, req, res.Error) - if cfg.Core.Sync { - resp.Logs = append(resp.Logs, errLog) - } + resp.Logs = append(resp.Logs, errLog) } } @@ -251,9 +217,7 @@ Retry: newTokens = append(newTokens, res.FailedRegistrationIDs...) errLog := logPush(cfg, core.FailedPush, notification.To, req, errors.New("device group: partial success or all fails")) - if cfg.Core.Sync { - resp.Logs = append(resp.Logs, errLog) - } + resp.Logs = append(resp.Logs, errLog) } if len(newTokens) > 0 && retryCount < maxRetry { diff --git a/notify/notification_hms.go b/notify/notification_hms.go index 1960067..31525ec 100644 --- a/notify/notification_hms.go +++ b/notify/notification_hms.go @@ -169,10 +169,6 @@ func GetHuaweiNotification(req PushNotification) (*model.MessageRequest, error) func PushToHuawei(req PushNotification, cfg config.ConfYaml) (resp *ResponsePush, err error) { logx.LogAccess.Debug("Start push notification for Huawei") - if cfg.Core.Sync && !core.IsLocalQueue(core.Queue(cfg.Queue.Engine)) { - cfg.Core.Sync = false - } - var ( client *client.HMSClient retryCount = 0