Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8b7fa18

Browse files
committed
Use UUID for notifier IDs
Fix test which uses coalesced fullname/username and was failingSigned-off-by: Danny Kopping <danny@coder.com>
1 parent49b2163 commit8b7fa18

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

‎coderd/notifications/manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (m *Manager) loop(ctx context.Context, notifiers int) error {
146146
fori:=0;i<notifiers;i++ {
147147
eg.Go(func()error {
148148
m.notifierMu.Lock()
149-
n:=newNotifier(ctx,m.cfg,i+1,m.log,m.store,m.handlers)
149+
n:=newNotifier(ctx,m.cfg,uuid.New(),m.log,m.store,m.handlers)
150150
m.notifiers=append(m.notifiers,n)
151151
m.notifierMu.Unlock()
152152
returnn.run(ctx,success,failure)
@@ -424,22 +424,22 @@ func (m *Manager) Stop(ctx context.Context) error {
424424
}
425425

426426
typedispatchResultstruct {
427-
notifierint
427+
notifieruuid.UUID
428428
msg uuid.UUID
429429
ts time.Time
430430
errerror
431431
retryablebool
432432
}
433433

434-
funcnewSuccessfulDispatch(notifierint,msg uuid.UUID)dispatchResult {
434+
funcnewSuccessfulDispatch(notifier,msg uuid.UUID)dispatchResult {
435435
returndispatchResult{
436436
notifier:notifier,
437437
msg:msg,
438438
ts:time.Now(),
439439
}
440440
}
441441

442-
funcnewFailedDispatch(notifierint,msg uuid.UUID,errerror,retryablebool)dispatchResult {
442+
funcnewFailedDispatch(notifier,msg uuid.UUID,errerror,retryablebool)dispatchResult {
443443
returndispatchResult{
444444
notifier:notifier,
445445
msg:msg,

‎coderd/notifications/notifications_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ func TestWebhookDispatch(t *testing.T) {
172172
require.Equal(t,*msgID,payload.MsgID)
173173
require.Equal(t,payload.Payload.Labels,input)
174174
require.Equal(t,payload.Payload.UserEmail,"bob@coder.com")
175-
require.Equal(t,payload.Payload.UserName,"bob")
175+
// UserName is coalesced from `name` and `username`; in this case `name` wins.
176+
require.Equal(t,payload.Payload.UserName,"Robert McBobbington")
176177
require.Equal(t,payload.Payload.NotificationName,"Workspace Deleted")
177178

178179
w.WriteHeader(http.StatusOK)
@@ -203,6 +204,7 @@ func TestWebhookDispatch(t *testing.T) {
203204
_,user:=coderdtest.CreateAnotherUserMutators(t,client,first.OrganizationID,nil,func(r*codersdk.CreateUserRequest) {
204205
r.Email="bob@coder.com"
205206
r.Username="bob"
207+
r.Name="Robert McBobbington"
206208
})
207209

208210
// when

‎coderd/notifications/notifier.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"sync"
77
"time"
88

9+
"github.com/google/uuid"
910
"golang.org/x/sync/errgroup"
1011
"golang.org/x/xerrors"
1112

@@ -21,7 +22,7 @@ import (
2122
// notifier is a consumer of the notifications_messages queue. It dequeues messages from that table and processes them
2223
// through a pipeline of fetch -> prepare -> render -> acquire handler -> deliver.
2324
typenotifierstruct {
24-
idint
25+
iduuid.UUID
2526
cfg codersdk.NotificationsConfig
2627
ctx context.Context
2728
log slog.Logger
@@ -35,7 +36,7 @@ type notifier struct {
3536
handlers*HandlerRegistry
3637
}
3738

38-
funcnewNotifier(ctx context.Context,cfg codersdk.NotificationsConfig,idint,log slog.Logger,dbStore,hr*HandlerRegistry)*notifier {
39+
funcnewNotifier(ctx context.Context,cfg codersdk.NotificationsConfig,iduuid.UUID,log slog.Logger,dbStore,hr*HandlerRegistry)*notifier {
3940
return&notifier{
4041
id:id,
4142
ctx:ctx,
@@ -63,7 +64,7 @@ func (n *notifier) run(ctx context.Context, success chan<- dispatchResult, failu
6364
for {
6465
select {
6566
case<-ctx.Done():
66-
returnxerrors.Errorf("notifier %d context canceled: %w",n.id,ctx.Err())
67+
returnxerrors.Errorf("notifier %q context canceled: %w",n.id,ctx.Err())
6768
case<-n.quit:
6869
returnnil
6970
default:
@@ -78,7 +79,7 @@ func (n *notifier) run(ctx context.Context, success chan<- dispatchResult, failu
7879
// Shortcut to bail out quickly if stop() has been called or the context canceled.
7980
select {
8081
case<-ctx.Done():
81-
returnxerrors.Errorf("notifier %d context canceled: %w",n.id,ctx.Err())
82+
returnxerrors.Errorf("notifier %q context canceled: %w",n.id,ctx.Err())
8283
case<-n.quit:
8384
returnnil
8485
case<-n.tick.C:
@@ -137,7 +138,7 @@ func (n *notifier) fetch(ctx context.Context) ([]database.AcquireNotificationMes
137138
msgs,err:=n.store.AcquireNotificationMessages(ctx, database.AcquireNotificationMessagesParams{
138139
Count:int32(n.cfg.LeaseCount),
139140
MaxAttemptCount:int32(n.cfg.MaxSendAttempts),
140-
NotifierID:int32(n.id),
141+
NotifierID:n.id,
141142
LeaseSeconds:int32(n.cfg.LeasePeriod.Value().Seconds()),
142143
})
143144
iferr!=nil {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp