Verbose provider specific logging

This commit is contained in:
LittleSheep 2024-11-26 21:46:03 +08:00
parent 9be096c9b7
commit 6716397a6f
4 changed files with 37 additions and 10 deletions

View File

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

View File

@ -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() {

View File

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

View File

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