Skip to content

Commit

Permalink
fix: unmarshal dlq messages correctly (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
smrz2001 authored Mar 6, 2024
1 parent d13d515 commit 1f3f2e9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions services/failure.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/json"
"fmt"

"github.com/google/uuid"

"github.com/ceramicnetwork/go-cas/models"
)

Expand All @@ -27,26 +29,30 @@ func (f FailureHandlingService) Failure(ctx context.Context, _ string) error {
func (f FailureHandlingService) DLQ(ctx context.Context, msgBody string) error {
f.metricService.Count(ctx, models.MetricName_FailureDlqMessage, 1)
msgType := "Unknown"
msgId := "Unknown"
// Unmarshal into one of the known message types
anchorReq := new(models.AnchorRequestMessage)
if err := json.Unmarshal([]byte(msgBody), anchorReq); err == nil {
if err := json.Unmarshal([]byte(msgBody), anchorReq); (err == nil) && (anchorReq.Id != uuid.Nil) {
msgType = "Anchor request"
msgId = anchorReq.Id.String()
f.logger.Debugw("dlq: dequeued",
msgType, anchorReq,
)
} else {
batchReq := new(models.AnchorBatchMessage)
if err = json.Unmarshal([]byte(msgBody), batchReq); err == nil {
if err = json.Unmarshal([]byte(msgBody), batchReq); (err == nil) && (batchReq.Id != uuid.Nil) {
msgType = "Batch request"
msgId = batchReq.Id.String()
f.logger.Debugw("dlq: dequeued",
msgType, batchReq,
)
}
}
text, _ := json.MarshalIndent(msgBody, "", "")
// Only include the message type and ID in the alert message since the message body is already logged, and Discord
// messages have a character limit.
return f.notif.SendAlert(
models.AlertTitle,
models.AlertDesc_DeadLetterQueue,
fmt.Sprintf(models.AlertFmt_DeadLetterQueue, msgType, text),
fmt.Sprintf(models.AlertFmt_DeadLetterQueue, msgType, msgId),
)
}

0 comments on commit 1f3f2e9

Please sign in to comment.