mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(coderd): add new dispatch logic for coder inbox (#16764)
This PR is [resolving the dispatch part of Coder Inbocx](https://github.com/coder/internal/issues/403). Since the DB layer has been merged - we now want to insert notifications into Coder Inbox in parallel of the other delivery target. To do so, we push two messages instead of one using the `Enqueue` method.
This commit is contained in:
@@ -38,6 +38,7 @@ func TestBufferedUpdates(t *testing.T) {
|
||||
|
||||
interceptor := &syncInterceptor{Store: store}
|
||||
santa := &santaHandler{}
|
||||
santaInbox := &santaHandler{}
|
||||
|
||||
cfg := defaultNotificationsConfig(database.NotificationMethodSmtp)
|
||||
cfg.StoreSyncInterval = serpent.Duration(time.Hour) // Ensure we don't sync the store automatically.
|
||||
@@ -45,9 +46,13 @@ func TestBufferedUpdates(t *testing.T) {
|
||||
// GIVEN: a manager which will pass or fail notifications based on their "nice" labels
|
||||
mgr, err := notifications.NewManager(cfg, interceptor, defaultHelpers(), createMetrics(), logger.Named("notifications-manager"))
|
||||
require.NoError(t, err)
|
||||
mgr.WithHandlers(map[database.NotificationMethod]notifications.Handler{
|
||||
database.NotificationMethodSmtp: santa,
|
||||
})
|
||||
|
||||
handlers := map[database.NotificationMethod]notifications.Handler{
|
||||
database.NotificationMethodSmtp: santa,
|
||||
database.NotificationMethodInbox: santaInbox,
|
||||
}
|
||||
|
||||
mgr.WithHandlers(handlers)
|
||||
enq, err := notifications.NewStoreEnqueuer(cfg, interceptor, defaultHelpers(), logger.Named("notifications-enqueuer"), quartz.NewReal())
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -79,7 +84,7 @@ func TestBufferedUpdates(t *testing.T) {
|
||||
// Wait for the expected number of buffered updates to be accumulated.
|
||||
require.Eventually(t, func() bool {
|
||||
success, failure := mgr.BufferedUpdatesCount()
|
||||
return success == expectedSuccess && failure == expectedFailure
|
||||
return success == expectedSuccess*len(handlers) && failure == expectedFailure*len(handlers)
|
||||
}, testutil.WaitShort, testutil.IntervalFast)
|
||||
|
||||
// Stop the manager which forces an update of buffered updates.
|
||||
@@ -93,8 +98,8 @@ func TestBufferedUpdates(t *testing.T) {
|
||||
ct.FailNow()
|
||||
}
|
||||
|
||||
assert.EqualValues(ct, expectedFailure, interceptor.failed.Load())
|
||||
assert.EqualValues(ct, expectedSuccess, interceptor.sent.Load())
|
||||
assert.EqualValues(ct, expectedFailure*len(handlers), interceptor.failed.Load())
|
||||
assert.EqualValues(ct, expectedSuccess*len(handlers), interceptor.sent.Load())
|
||||
}, testutil.WaitMedium, testutil.IntervalFast)
|
||||
}
|
||||
|
||||
@@ -229,7 +234,7 @@ type enqueueInterceptor struct {
|
||||
}
|
||||
|
||||
func newEnqueueInterceptor(db notifications.Store, metadataFn func() database.FetchNewMessageMetadataRow) *enqueueInterceptor {
|
||||
return &enqueueInterceptor{Store: db, payload: make(chan types.MessagePayload, 1), metadataFn: metadataFn}
|
||||
return &enqueueInterceptor{Store: db, payload: make(chan types.MessagePayload, 2), metadataFn: metadataFn}
|
||||
}
|
||||
|
||||
func (e *enqueueInterceptor) EnqueueNotificationMessage(_ context.Context, arg database.EnqueueNotificationMessageParams) error {
|
||||
|
||||
Reference in New Issue
Block a user