From 5da4c3d3b9f369faa92b9de979db6c03d8e1a3b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Mon, 16 Sep 2024 17:55:13 +0200 Subject: [PATCH] Fix dbConverter error when unmarshalling (failed) deliveries --- scnserver/TODO.md | 5 +++++ scnserver/db/impl/primary/deliveries.go | 7 ++++--- scnserver/models/delivery.go | 22 ++++++++++++---------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/scnserver/TODO.md b/scnserver/TODO.md index c21348b..129cc43 100644 --- a/scnserver/TODO.md +++ b/scnserver/TODO.md @@ -12,6 +12,11 @@ - exerr.New | exerr.Wrap + - Properly handle UNREGISTERED firebase error (remove token from client?) + WRN logic/application.go:284 > FCM Delivery failed error="FCM-Request returned 404: + { \"error\": {\n \"code\": 404,\n \"message\": \"Requested entity was not found.\",\n \"status\": \"NOT_FOUND\",\n \"details\": [\n {\n \"@type\": \"type.googleapis.com/google.firebase.fcm.v1.FcmError\",\n \"errorCode\": \"UNREGISTERED\"\n }\n ]\n }\n}\n" + ClientID=CLNGOSVIaCnm5cQmCI0pC5kR MessageID=MSG8w7NvVRm0OtJERnJlEe3C + #### UNSURE - (?) default-priority for channels diff --git a/scnserver/db/impl/primary/deliveries.go b/scnserver/db/impl/primary/deliveries.go index 94ee239..ae3d5cd 100644 --- a/scnserver/db/impl/primary/deliveries.go +++ b/scnserver/db/impl/primary/deliveries.go @@ -5,6 +5,7 @@ import ( "blackforestbytes.com/simplecloudnotifier/db" "blackforestbytes.com/simplecloudnotifier/models" "gogs.mikescher.com/BlackForestBytes/goext/langext" + "gogs.mikescher.com/BlackForestBytes/goext/rfctime" "gogs.mikescher.com/BlackForestBytes/goext/sq" "time" ) @@ -27,7 +28,7 @@ func (db *Database) CreateRetryDelivery(ctx db.TxContext, client models.Client, TimestampFinalized: nil, Status: models.DeliveryStatusRetry, RetryCount: 0, - NextDelivery: models.NewSCNTimePtr(&next), + NextDelivery: rfctime.NewRFC3339NanoPtr(&next), FCMMessageID: nil, } @@ -75,7 +76,7 @@ func (db *Database) ListRetrieableDeliveries(ctx db.TxContext, pageSize int) ([] } return sq.QueryAll[models.Delivery](ctx, tx, "SELECT * FROM deliveries WHERE status = 'RETRY' AND next_delivery < :next ORDER BY next_delivery ASC LIMIT :lim", sq.PP{ - "next": time2DB(time.Now()), + "next": time.Now().Format(time.RFC3339Nano), "lim": pageSize, }, sq.SModeExtended, sq.Safe) } @@ -125,7 +126,7 @@ func (db *Database) SetDeliveryRetry(ctx db.TxContext, delivery models.Delivery) } _, err = tx.Exec(ctx, "UPDATE deliveries SET status = 'RETRY', next_delivery = :next, retry_count = :rc WHERE delivery_id = :did", sq.PP{ - "next": scn.NextDeliveryTimestamp(time.Now()), + "next": scn.NextDeliveryTimestamp(time.Now()).Format(time.RFC3339Nano), "rc": delivery.RetryCount + 1, "did": delivery.DeliveryID, }) diff --git a/scnserver/models/delivery.go b/scnserver/models/delivery.go index ce51910..e19cf67 100644 --- a/scnserver/models/delivery.go +++ b/scnserver/models/delivery.go @@ -1,5 +1,7 @@ package models +import "gogs.mikescher.com/BlackForestBytes/goext/rfctime" + type DeliveryStatus string //@enum:type const ( @@ -9,16 +11,16 @@ const ( ) type Delivery struct { - DeliveryID DeliveryID `db:"delivery_id" json:"delivery_id"` - MessageID MessageID `db:"message_id" json:"message_id"` - ReceiverUserID UserID `db:"receiver_user_id" json:"receiver_user_id"` - ReceiverClientID ClientID `db:"receiver_client_id" json:"receiver_client_id"` - TimestampCreated SCNTime `db:"timestamp_created" json:"timestamp_created"` - TimestampFinalized *SCNTime `db:"timestamp_finalized" json:"timestamp_finalized"` - Status DeliveryStatus `db:"status" json:"status"` - RetryCount int `db:"retry_count" json:"retry_count"` - NextDelivery *SCNTime `db:"next_delivery" json:"next_delivery"` - FCMMessageID *string `db:"fcm_message_id" json:"fcm_message_id"` + DeliveryID DeliveryID `db:"delivery_id" json:"delivery_id"` + MessageID MessageID `db:"message_id" json:"message_id"` + ReceiverUserID UserID `db:"receiver_user_id" json:"receiver_user_id"` + ReceiverClientID ClientID `db:"receiver_client_id" json:"receiver_client_id"` + TimestampCreated SCNTime `db:"timestamp_created" json:"timestamp_created"` + TimestampFinalized *SCNTime `db:"timestamp_finalized" json:"timestamp_finalized"` + Status DeliveryStatus `db:"status" json:"status"` + RetryCount int `db:"retry_count" json:"retry_count"` + NextDelivery *rfctime.RFC3339NanoTime `db:"next_delivery" json:"next_delivery"` + FCMMessageID *string `db:"fcm_message_id" json:"fcm_message_id"` } func (d Delivery) MaxRetryCount() int {