diff --git a/internal/worker/notifications.go b/internal/worker/notifications.go index 750af91..30156a4 100644 --- a/internal/worker/notifications.go +++ b/internal/worker/notifications.go @@ -327,13 +327,23 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { } res, err := client.Push(notification) - if err != nil || !res.Sent() { + if err != nil { _ = nc.statsd.Incr("apns.notification.errors", []string{}, 1) nc.logger.Error("failed to send notification", zap.Error(err), zap.Int64("account#id", id), zap.String("account#username", account.NormalizedUsername()), zap.String("device#token", device.APNSToken), + ) + + // Delete device as notifications might have been disabled here + _ = nc.deviceRepo.Delete(nc, device.APNSToken) + } else if !res.Sent() { + _ = nc.statsd.Incr("apns.notification.errors", []string{}, 1) + nc.logger.Error("notification not sent", + zap.Int64("account#id", id), + zap.String("account#username", account.NormalizedUsername()), + zap.String("device#token", device.APNSToken), zap.Int("response#status", res.StatusCode), zap.String("response#reason", res.Reason), ) diff --git a/internal/worker/subreddits.go b/internal/worker/subreddits.go index 42814b4..f462c2c 100644 --- a/internal/worker/subreddits.go +++ b/internal/worker/subreddits.go @@ -412,7 +412,7 @@ func (sc *subredditsConsumer) Consume(delivery rmq.Delivery) { } res, err := client.Push(notification) - if err != nil || !res.Sent() { + if err != nil { _ = sc.statsd.Incr("apns.notification.errors", []string{}, 1) sc.logger.Error("failed to send notification", zap.Error(err), @@ -420,6 +420,14 @@ func (sc *subredditsConsumer) Consume(delivery rmq.Delivery) { zap.String("subreddit#name", subreddit.NormalizedName()), zap.String("post#id", post.ID), zap.String("apns", watcher.Device.APNSToken), + ) + } else if !res.Sent() { + _ = sc.statsd.Incr("apns.notification.errors", []string{}, 1) + sc.logger.Error("notificaion not sent", + zap.Int64("subreddit#id", id), + zap.String("subreddit#name", subreddit.NormalizedName()), + zap.String("post#id", post.ID), + zap.String("apns", watcher.Device.APNSToken), zap.Int("response#status", res.StatusCode), zap.String("response#reason", res.Reason), ) diff --git a/internal/worker/trending.go b/internal/worker/trending.go index 04554c5..fd2b659 100644 --- a/internal/worker/trending.go +++ b/internal/worker/trending.go @@ -291,7 +291,7 @@ func (tc *trendingConsumer) Consume(delivery rmq.Delivery) { } res, err := client.Push(notification) - if err != nil || !res.Sent() { + if err != nil { _ = tc.statsd.Incr("apns.notification.errors", []string{}, 1) tc.logger.Error("failed to send notification", zap.Error(err), @@ -299,6 +299,14 @@ func (tc *trendingConsumer) Consume(delivery rmq.Delivery) { zap.String("subreddit#name", subreddit.NormalizedName()), zap.String("post#id", post.ID), zap.String("apns", watcher.Device.APNSToken), + ) + } else if !res.Sent() { + _ = tc.statsd.Incr("apns.notification.errors", []string{}, 1) + tc.logger.Error("notification not sent", + zap.Int64("subreddit#id", id), + zap.String("subreddit#name", subreddit.NormalizedName()), + zap.String("post#id", post.ID), + zap.String("apns", watcher.Device.APNSToken), zap.Int("response#status", res.StatusCode), zap.String("response#reason", res.Reason), )