Skip to content

Commit

Permalink
Fix the thread update to not throw errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AchoArnold committed Oct 10, 2023
1 parent 431c2cf commit 3e3e5bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/pkg/services/message_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,8 @@ func (service *MessageService) HandleMessageDelivered(ctx context.Context, param

if !message.IsSent() && !message.IsSending() && !message.IsExpired() && !message.IsScheduled() {
msg := fmt.Sprintf("message has wrong status [%s]. expected [%s, %s, %s, %s]", message.Status, entities.MessageStatusSent, entities.MessageStatusScheduled, entities.MessageStatusSending, entities.MessageStatusExpired)
return service.tracer.WrapErrorSpan(span, stacktrace.NewError(msg))
ctxLogger.Warn(stacktrace.NewError(msg))
return nil
}

if err = service.repository.Update(ctx, message.Delivered(params.Timestamp)); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion api/pkg/services/message_thread_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ func (service *MessageThreadService) UpdateThread(ctx context.Context, params Me
}

if thread.OrderTimestamp.Unix() > params.Timestamp.Unix() && thread.Status != entities.MessageStatusSending {
ctxLogger.Info(fmt.Sprintf("thread [%s] has timestamp [%s] and status [%s] which is greater than timestamp [%s] for message [%s] and status [%s]", thread.ID, thread.OrderTimestamp, thread.Status, params.Timestamp, params.MessageID, params.Status))
ctxLogger.Warn(stacktrace.NewError(fmt.Sprintf("thread [%s] has timestamp [%s] and status [%s] which is greater than timestamp [%s] for message [%s] and status [%s]", thread.ID, thread.OrderTimestamp, thread.Status, params.Timestamp, params.MessageID, params.Status)))
return nil
}

if thread.Status == entities.MessageStatusDelivered {
ctxLogger.Warn(stacktrace.NewError(fmt.Sprintf("thread [%s] already has status [%s] not updating with status [%s] for message [%s]", thread.ID, thread.Status, params.Status, params.MessageID)))
return nil
}

Expand Down

0 comments on commit 3e3e5bd

Please sign in to comment.