Skip to content

Commit bbcbcf2

Browse files
committed
Clarification on enqueue failure
Test fix Signed-off-by: Danny Kopping <danny@coder.com>
1 parent 511b418 commit bbcbcf2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

coderd/notifications/enqueuer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ func (s *StoreEnqueuer) Enqueue(ctx context.Context, userID, templateID uuid.UUI
8383
CreatedBy: createdBy,
8484
})
8585
if err != nil {
86+
// We have a trigger on the notification_messages table named `inhibit_enqueue_if_disabled` which prevents messages
87+
// from being enqueued if the user has disabled them via notification_preferences. The trigger will fail the insertion
88+
// with the message "cannot enqueue message: user has disabled this notification".
89+
//
90+
// This is more efficient than fetching the user's preferences for each enqueue, and centralizes the business logic.
8691
if strings.Contains(err.Error(), ErrCannotEnqueueDisabledNotification.Error()) {
8792
return nil, ErrCannotEnqueueDisabledNotification
8893
}

coderd/notifications/notifications_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,9 @@ func TestCustomNotificationMethod(t *testing.T) {
886886
require.NoError(t, err)
887887
require.EventuallyWithT(t, func(ct *assert.CollectT) {
888888
msgs := mockSMTPSrv.MessagesAndPurge()
889-
assert.Len(ct, msgs, 1)
890-
assert.Contains(ct, msgs[0].MsgRequest(), fmt.Sprintf("Message-Id: %s", msgID))
889+
if assert.Len(ct, msgs, 1) {
890+
assert.Contains(ct, msgs[0].MsgRequest(), fmt.Sprintf("Message-Id: %s", msgID))
891+
}
891892
}, testutil.WaitLong, testutil.IntervalFast)
892893
}
893894

0 commit comments

Comments
 (0)