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

View File

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

View File

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