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)
}
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
}

View File

@ -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)
}
status.StatStorage.AddIosError(1)
// 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/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)
}
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)
}
}
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)
}
continue
}
@ -240,21 +208,17 @@ Retry:
} else {
// failure
errLog := logPush(cfg, core.FailedPush, to, req, res.Error)
if cfg.Core.Sync {
resp.Logs = append(resp.Logs, errLog)
}
}
}
// Device Group HTTP Response
if len(res.FailedRegistrationIDs) > 0 {
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)
}
}
if len(newTokens) > 0 && retryCount < maxRetry {
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) {
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