diff --git a/courier/message.go b/courier/message.go index 9cf4399cc8b9..9ba9cf9cdb6c 100644 --- a/courier/message.go +++ b/courier/message.go @@ -24,14 +24,15 @@ type MessageStatus int const ( MessageStatusQueued MessageStatus = iota + 1 MessageStatusSent - _ + MessageStatusProcessing MessageStatusAbandoned ) const ( - messageStatusQueuedText = "queued" - messageStatusSentText = "sent" - messageStatusAbandonedText = "abandoned" + messageStatusQueuedText = "queued" + messageStatusSentText = "sent" + messageStatusProcessingText = "processing" + messageStatusAbandonedText = "abandoned" ) func ToMessageStatus(str string) (MessageStatus, error) { @@ -40,6 +41,8 @@ func ToMessageStatus(str string) (MessageStatus, error) { return MessageStatusQueued, nil case s.AddCase(MessageStatusSent.String()): return MessageStatusSent, nil + case s.AddCase(MessageStatusProcessing.String()): + return MessageStatusProcessing, nil case s.AddCase(MessageStatusAbandoned.String()): return MessageStatusAbandoned, nil default: @@ -53,6 +56,8 @@ func (ms MessageStatus) String() string { return messageStatusQueuedText case MessageStatusSent: return messageStatusSentText + case MessageStatusProcessing: + return messageStatusProcessingText case MessageStatusAbandoned: return messageStatusAbandonedText default: @@ -62,7 +67,7 @@ func (ms MessageStatus) String() string { func (ms MessageStatus) IsValid() error { switch ms { - case MessageStatusQueued, MessageStatusSent, MessageStatusAbandoned: + case MessageStatusQueued, MessageStatusSent, MessageStatusProcessing, MessageStatusAbandoned: return nil default: return errors.WithStack(herodot.ErrBadRequest.WithReason("Message status is not valid")) diff --git a/courier/message_test.go b/courier/message_test.go index bb3af52ab71c..e8db6713bcf5 100644 --- a/courier/message_test.go +++ b/courier/message_test.go @@ -20,9 +20,10 @@ func TestMessageStatusValidity(t *testing.T) { func TestToMessageStatus(t *testing.T) { t.Run("case=should return corresponding MessageStatus for given str", func(t *testing.T) { for str, exp := range map[string]courier.MessageStatus{ - "queued": courier.MessageStatusQueued, - "sent": courier.MessageStatusSent, - "abandoned": courier.MessageStatusAbandoned, + "queued": courier.MessageStatusQueued, + "sent": courier.MessageStatusSent, + "processing": courier.MessageStatusProcessing, + "abandoned": courier.MessageStatusAbandoned, } { result, err := courier.ToMessageStatus(str) require.NoError(t, err) diff --git a/courier/persistence.go b/courier/persistence.go index a8547327250a..6bb2d4fa6230 100644 --- a/courier/persistence.go +++ b/courier/persistence.go @@ -5,12 +5,15 @@ package courier import ( "context" + "errors" "github.com/gofrs/uuid" "github.com/ory/x/pagination/keysetpagination" ) +var ErrQueueEmpty = errors.New("queue is empty") + type ( Persister interface { AddMessage(context.Context, *Message) error