From 6716397a6fb367ed629320c11d66013a59f1c9ae Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 26 Nov 2024 21:46:03 +0800 Subject: [PATCH] :sparkles: Verbose provider specific logging --- pkg/internal/provider/apns.go | 15 ++++++++++++++- pkg/internal/provider/caller.go | 10 ++++++++++ pkg/internal/provider/firebase.go | 8 +++++++- pkg/internal/scheduler/dispatch.go | 14 ++++++-------- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/pkg/internal/provider/apns.go b/pkg/internal/provider/apns.go index 53c31dc..6041495 100644 --- a/pkg/internal/provider/apns.go +++ b/pkg/internal/provider/apns.go @@ -2,6 +2,7 @@ package provider import ( "git.solsynth.dev/hypernet/pusher/pkg/pushkit" + "github.com/rs/zerolog/log" "github.com/sideshow/apns2" payload2 "github.com/sideshow/apns2/payload" "github.com/spf13/viper" @@ -39,7 +40,19 @@ func (v *AppleNotifyProvider) Push(in pushkit.Notification, tk string) error { Topic: viper.GetString(v.topic), Payload: rawData, } - _, err = v.conn.Push(payload) + + resp, err := v.conn.Push(payload) + if resp != nil { + log.Debug(). + Str("token", tk). + Str("remote_id", resp.ApnsID). + Str("remote_uuid", resp.ApnsUniqueID). + Int("status", resp.StatusCode). + Time("timestamp", resp.Timestamp.Time). + Str("reason", resp.Reason). + Msg("Pushed once notification to apple") + } + return err } diff --git a/pkg/internal/provider/caller.go b/pkg/internal/provider/caller.go index db3a385..f1594f0 100644 --- a/pkg/internal/provider/caller.go +++ b/pkg/internal/provider/caller.go @@ -26,6 +26,11 @@ func PushNotification(in pushkit.NotificationPushRequest) error { prov, ok := notifyProviders[in.Provider] if !ok { + log.Warn(). + Str("provider", in.Provider). + Str("topic", in.Notification.Topic). + Str("request_id", requestId). + Msg("Provider was not found, push skipped...") return fmt.Errorf("provider not found") } start := time.Now() @@ -62,6 +67,11 @@ func PushNotificationBatch(in pushkit.NotificationPushBatchRequest) { for idx, key := range in.Providers { prov, ok := notifyProviders[key] if !ok { + log.Warn(). + Str("provider", key). + Str("topic", in.Notification.Topic). + Str("request_id", requestId). + Msg("Provider was not found, push skipped...") continue } go func() { diff --git a/pkg/internal/provider/firebase.go b/pkg/internal/provider/firebase.go index a582fb8..477348c 100644 --- a/pkg/internal/provider/firebase.go +++ b/pkg/internal/provider/firebase.go @@ -6,6 +6,7 @@ import ( "firebase.google.com/go/messaging" "fmt" "git.solsynth.dev/hypernet/pusher/pkg/pushkit" + "github.com/rs/zerolog/log" ) type FirebaseNotifyProvider struct { @@ -31,7 +32,12 @@ func (v *FirebaseNotifyProvider) Push(in pushkit.Notification, tk string) error Token: tk, } - _, err = client.Send(ctx, message) + resp, err := client.Send(ctx, message) + log.Debug(). + Str("token", tk). + Str("response", resp). + Msg("Pushed once notification to firebase") + return err } diff --git a/pkg/internal/scheduler/dispatch.go b/pkg/internal/scheduler/dispatch.go index b3f9ee8..8bd37d8 100644 --- a/pkg/internal/scheduler/dispatch.go +++ b/pkg/internal/scheduler/dispatch.go @@ -30,7 +30,7 @@ func SubscribeToQueue() error { return } - go provider.PushNotification(req) + provider.PushNotification(req) }) if err != nil { return fmt.Errorf("failed to subscribe notification topic: %v", err) @@ -46,7 +46,7 @@ func SubscribeToQueue() error { return } - go provider.PushNotificationBatch(req) + provider.PushNotificationBatch(req) }) if err != nil { return fmt.Errorf("failed to subscribe notification batch topic: %v", err) @@ -62,7 +62,7 @@ func SubscribeToQueue() error { return } - go provider.SendMail(req.To, req.Email) + provider.SendMail(req.To, req.Email) }) if err != nil { return fmt.Errorf("failed to subscribe email topic: %v", err) @@ -78,11 +78,9 @@ func SubscribeToQueue() error { return } - go func() { - for _, to := range req.To { - _ = provider.SendMail(to, req.Email) - } - }() + for _, to := range req.To { + _ = provider.SendMail(to, req.Email) + } }) if err != nil { return fmt.Errorf("failed to subscribe email batch topic: %v", err)