Skip to content

Commit fcd6d61

Browse files
committed
notif data
1 parent 8aa1d9a commit fcd6d61

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

coderd/autobuild/lifecycle_executor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ func (e *Executor) runOnce(t time.Time) Stats {
303303
"reason": nextBuildReason,
304304
"template_version_name": activeTemplateVersion.Name,
305305
"template_version_message": activeTemplateVersion.Message,
306-
}, "autobuild",
306+
},
307+
"autobuild",
307308
// Associate this notification with all the related entities.
308309
ws.ID, ws.OwnerID, ws.TemplateID, ws.OrganizationID,
309310
); err != nil {

coderd/notifications/enqueuer.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@ func NewStoreEnqueuer(cfg codersdk.NotificationsConfig, store Store, helpers tem
5252
}, nil
5353
}
5454

55+
// Enqueue queues a notification message for later delivery, assumes no structured input data.
56+
func (s *StoreEnqueuer) Enqueue(ctx context.Context, userID, templateID uuid.UUID, labels map[string]string, createdBy string, targets ...uuid.UUID) (*uuid.UUID, error) {
57+
return s.EnqueueData(ctx, userID, templateID, labels, map[string]any{}, createdBy, targets...)
58+
}
59+
5560
// Enqueue queues a notification message for later delivery.
5661
// Messages will be dequeued by a notifier later and dispatched.
57-
func (s *StoreEnqueuer) Enqueue(ctx context.Context, userID, templateID uuid.UUID, labels map[string]string, createdBy string, targets ...uuid.UUID) (*uuid.UUID, error) {
62+
func (s *StoreEnqueuer) EnqueueData(ctx context.Context, userID, templateID uuid.UUID, labels map[string]string, data map[string]any, createdBy string, targets ...uuid.UUID) (*uuid.UUID, error) {
5863
metadata, err := s.store.FetchNewMessageMetadata(ctx, database.FetchNewMessageMetadataParams{
5964
UserID: userID,
6065
NotificationTemplateID: templateID,
@@ -69,7 +74,6 @@ func (s *StoreEnqueuer) Enqueue(ctx context.Context, userID, templateID uuid.UUI
6974
dispatchMethod = metadata.CustomMethod.NotificationMethod
7075
}
7176

72-
data := map[string]any{} // FIXME
7377
payload, err := s.buildPayload(metadata, labels, data)
7478
if err != nil {
7579
s.log.Warn(ctx, "failed to build payload", slog.F("template_id", templateID), slog.F("user_id", userID), slog.Error(err))

coderd/notifications/spec.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ type Handler interface {
3333
// Enqueuer enqueues a new notification message in the store and returns its ID, should it enqueue without failure.
3434
type Enqueuer interface {
3535
Enqueue(ctx context.Context, userID, templateID uuid.UUID, labels map[string]string, createdBy string, targets ...uuid.UUID) (*uuid.UUID, error)
36+
EnqueueData(ctx context.Context, userID, templateID uuid.UUID, labels map[string]string, data map[string]any, createdBy string, targets ...uuid.UUID) (*uuid.UUID, error)
3637
}

testutil/notifications.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,24 @@ type FakeNotificationsEnqueuer struct {
1515
type Notification struct {
1616
UserID, TemplateID uuid.UUID
1717
Labels map[string]string
18+
Data map[string]any
1819
CreatedBy string
1920
Targets []uuid.UUID
2021
}
2122

22-
func (f *FakeNotificationsEnqueuer) Enqueue(_ context.Context, userID, templateID uuid.UUID, labels map[string]string, createdBy string, targets ...uuid.UUID) (*uuid.UUID, error) {
23+
func (f *FakeNotificationsEnqueuer) Enqueue(ctx context.Context, userID, templateID uuid.UUID, labels map[string]string, createdBy string, targets ...uuid.UUID) (*uuid.UUID, error) {
24+
return f.EnqueueData(ctx, userID, templateID, labels, map[string]any{}, createdBy, targets...)
25+
}
26+
27+
func (f *FakeNotificationsEnqueuer) EnqueueData(_ context.Context, userID, templateID uuid.UUID, labels map[string]string, data map[string]any, createdBy string, targets ...uuid.UUID) (*uuid.UUID, error) {
2328
f.mu.Lock()
2429
defer f.mu.Unlock()
2530

2631
f.Sent = append(f.Sent, &Notification{
2732
UserID: userID,
2833
TemplateID: templateID,
2934
Labels: labels,
35+
Data: data,
3036
CreatedBy: createdBy,
3137
Targets: targets,
3238
})

0 commit comments

Comments
 (0)