Fix dbConverter error when unmarshalling (failed) deliveries
All checks were successful
Build Docker and Deploy / Build Docker Container (push) Successful in 1m48s
Build Docker and Deploy / Deploy to Server (push) Successful in 5s

This commit is contained in:
Mike Schwörer 2024-09-16 17:55:13 +02:00
parent fb1560a1f5
commit 5da4c3d3b9
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
3 changed files with 21 additions and 13 deletions

View File

@ -12,6 +12,11 @@
- exerr.New | exerr.Wrap - 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 #### UNSURE
- (?) default-priority for channels - (?) default-priority for channels

View File

@ -5,6 +5,7 @@ import (
"blackforestbytes.com/simplecloudnotifier/db" "blackforestbytes.com/simplecloudnotifier/db"
"blackforestbytes.com/simplecloudnotifier/models" "blackforestbytes.com/simplecloudnotifier/models"
"gogs.mikescher.com/BlackForestBytes/goext/langext" "gogs.mikescher.com/BlackForestBytes/goext/langext"
"gogs.mikescher.com/BlackForestBytes/goext/rfctime"
"gogs.mikescher.com/BlackForestBytes/goext/sq" "gogs.mikescher.com/BlackForestBytes/goext/sq"
"time" "time"
) )
@ -27,7 +28,7 @@ func (db *Database) CreateRetryDelivery(ctx db.TxContext, client models.Client,
TimestampFinalized: nil, TimestampFinalized: nil,
Status: models.DeliveryStatusRetry, Status: models.DeliveryStatusRetry,
RetryCount: 0, RetryCount: 0,
NextDelivery: models.NewSCNTimePtr(&next), NextDelivery: rfctime.NewRFC3339NanoPtr(&next),
FCMMessageID: nil, 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{ 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, "lim": pageSize,
}, sq.SModeExtended, sq.Safe) }, 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{ _, 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, "rc": delivery.RetryCount + 1,
"did": delivery.DeliveryID, "did": delivery.DeliveryID,
}) })

View File

@ -1,5 +1,7 @@
package models package models
import "gogs.mikescher.com/BlackForestBytes/goext/rfctime"
type DeliveryStatus string //@enum:type type DeliveryStatus string //@enum:type
const ( const (
@ -17,7 +19,7 @@ type Delivery struct {
TimestampFinalized *SCNTime `db:"timestamp_finalized" json:"timestamp_finalized"` TimestampFinalized *SCNTime `db:"timestamp_finalized" json:"timestamp_finalized"`
Status DeliveryStatus `db:"status" json:"status"` Status DeliveryStatus `db:"status" json:"status"`
RetryCount int `db:"retry_count" json:"retry_count"` RetryCount int `db:"retry_count" json:"retry_count"`
NextDelivery *SCNTime `db:"next_delivery" json:"next_delivery"` NextDelivery *rfctime.RFC3339NanoTime `db:"next_delivery" json:"next_delivery"`
FCMMessageID *string `db:"fcm_message_id" json:"fcm_message_id"` FCMMessageID *string `db:"fcm_message_id" json:"fcm_message_id"`
} }