chore(push): send error to specific URL (#621)

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2021-08-02 12:37:38 +08:00 committed by GitHub
parent 3feeeb796d
commit 6d65c1ea6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 60 deletions

View File

@ -250,6 +250,15 @@ func SendNotification(req queue.QueuedMessage, cfg config.ConfYaml) (resp *Respo
resp, err = PushToHuawei(*v, cfg) 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 return
} }

View File

@ -21,7 +21,6 @@ import (
"github.com/sideshow/apns2/certificate" "github.com/sideshow/apns2/certificate"
"github.com/sideshow/apns2/payload" "github.com/sideshow/apns2/payload"
"github.com/sideshow/apns2/token" "github.com/sideshow/apns2/token"
"github.com/sirupsen/logrus"
"golang.org/x/net/http2" "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) { func PushToIOS(req PushNotification, cfg config.ConfYaml) (resp *ResponsePush, err error) {
logx.LogAccess.Debug("Start push notification for iOS") logx.LogAccess.Debug("Start push notification for iOS")
if cfg.Core.Sync && !core.IsLocalQueue(core.Queue(cfg.Queue.Engine)) {
cfg.Core.Sync = false
}
var ( var (
retryCount = 0 retryCount = 0
maxRetry = cfg.Ios.MaxRetry maxRetry = cfg.Ios.MaxRetry
@ -431,16 +426,7 @@ Retry:
// apns server error // apns server error
errLog := logPush(cfg, core.FailedPush, token, req, err) errLog := logPush(cfg, core.FailedPush, token, req, err)
if cfg.Core.Sync {
resp.Logs = append(resp.Logs, errLog) 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)
}
status.StatStorage.AddIosError(1) status.StatStorage.AddIosError(1)
// We should retry only "retryable" statuses. More info about response: // We should retry only "retryable" statuses. More info about response:

View File

@ -10,7 +10,6 @@ import (
"github.com/appleboy/gorush/status" "github.com/appleboy/gorush/status"
"github.com/appleboy/go-fcm" "github.com/appleboy/go-fcm"
"github.com/sirupsen/logrus"
) )
// InitFCMClient use for initialize FCM Client. // 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) { func PushToAndroid(req PushNotification, cfg config.ConfYaml) (resp *ResponsePush, err error) {
logx.LogAccess.Debug("Start push notification for Android") logx.LogAccess.Debug("Start push notification for Android")
if cfg.Core.Sync && !core.IsLocalQueue(core.Queue(cfg.Queue.Engine)) {
cfg.Core.Sync = false
}
var ( var (
client *fcm.Client client *fcm.Client
retryCount = 0 retryCount = 0
@ -154,30 +149,12 @@ Retry:
if req.IsTopic() { if req.IsTopic() {
errLog := logPush(cfg, core.FailedPush, req.To, req, err) errLog := logPush(cfg, core.FailedPush, req.To, req, err)
if cfg.Core.Sync {
resp.Logs = append(resp.Logs, errLog) 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)
}
status.StatStorage.AddAndroidError(1) status.StatStorage.AddAndroidError(1)
} else { } else {
for _, token := range req.Tokens { for _, token := range req.Tokens {
errLog := logPush(cfg, core.FailedPush, token, req, err) errLog := logPush(cfg, core.FailedPush, token, req, err)
if cfg.Core.Sync {
resp.Logs = append(resp.Logs, errLog) 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)
}
} }
status.StatStorage.AddAndroidError(int64(len(req.Tokens))) status.StatStorage.AddAndroidError(int64(len(req.Tokens)))
} }
@ -209,16 +186,7 @@ Retry:
} }
errLog := logPush(cfg, core.FailedPush, to, req, result.Error) errLog := logPush(cfg, core.FailedPush, to, req, result.Error)
if cfg.Core.Sync {
resp.Logs = append(resp.Logs, errLog) 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)
}
continue continue
} }
@ -240,21 +208,17 @@ Retry:
} else { } else {
// failure // failure
errLog := logPush(cfg, core.FailedPush, to, req, res.Error) 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)
} }
} }
}
// Device Group HTTP Response // Device Group HTTP Response
if len(res.FailedRegistrationIDs) > 0 { if len(res.FailedRegistrationIDs) > 0 {
newTokens = append(newTokens, res.FailedRegistrationIDs...) newTokens = append(newTokens, res.FailedRegistrationIDs...)
errLog := logPush(cfg, core.FailedPush, notification.To, req, errors.New("device group: partial success or all fails")) 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 { if len(newTokens) > 0 && retryCount < maxRetry {
retryCount++ retryCount++

View File

@ -169,10 +169,6 @@ func GetHuaweiNotification(req PushNotification) (*model.MessageRequest, error)
func PushToHuawei(req PushNotification, cfg config.ConfYaml) (resp *ResponsePush, err error) { func PushToHuawei(req PushNotification, cfg config.ConfYaml) (resp *ResponsePush, err error) {
logx.LogAccess.Debug("Start push notification for Huawei") logx.LogAccess.Debug("Start push notification for Huawei")
if cfg.Core.Sync && !core.IsLocalQueue(core.Queue(cfg.Queue.Engine)) {
cfg.Core.Sync = false
}
var ( var (
client *client.HMSClient client *client.HMSClient
retryCount = 0 retryCount = 0