6
6
"sync"
7
7
"time"
8
8
9
+ "github.com/google/uuid"
9
10
"golang.org/x/sync/errgroup"
10
11
"golang.org/x/xerrors"
11
12
@@ -21,7 +22,7 @@ import (
21
22
// notifier is a consumer of the notifications_messages queue. It dequeues messages from that table and processes them
22
23
// through a pipeline of fetch -> prepare -> render -> acquire handler -> deliver.
23
24
type notifier struct {
24
- id int
25
+ id uuid. UUID
25
26
cfg codersdk.NotificationsConfig
26
27
ctx context.Context
27
28
log slog.Logger
@@ -35,7 +36,7 @@ type notifier struct {
35
36
handlers * HandlerRegistry
36
37
}
37
38
38
- func newNotifier (ctx context.Context , cfg codersdk.NotificationsConfig , id int , log slog.Logger , db Store , hr * HandlerRegistry ) * notifier {
39
+ func newNotifier (ctx context.Context , cfg codersdk.NotificationsConfig , id uuid. UUID , log slog.Logger , db Store , hr * HandlerRegistry ) * notifier {
39
40
return & notifier {
40
41
id : id ,
41
42
ctx : ctx ,
@@ -63,7 +64,7 @@ func (n *notifier) run(ctx context.Context, success chan<- dispatchResult, failu
63
64
for {
64
65
select {
65
66
case <- ctx .Done ():
66
- return xerrors .Errorf ("notifier %d context canceled: %w" , n .id , ctx .Err ())
67
+ return xerrors .Errorf ("notifier %q context canceled: %w" , n .id , ctx .Err ())
67
68
case <- n .quit :
68
69
return nil
69
70
default :
@@ -78,7 +79,7 @@ func (n *notifier) run(ctx context.Context, success chan<- dispatchResult, failu
78
79
// Shortcut to bail out quickly if stop() has been called or the context canceled.
79
80
select {
80
81
case <- ctx .Done ():
81
- return xerrors .Errorf ("notifier %d context canceled: %w" , n .id , ctx .Err ())
82
+ return xerrors .Errorf ("notifier %q context canceled: %w" , n .id , ctx .Err ())
82
83
case <- n .quit :
83
84
return nil
84
85
case <- n .tick .C :
@@ -137,7 +138,7 @@ func (n *notifier) fetch(ctx context.Context) ([]database.AcquireNotificationMes
137
138
msgs , err := n .store .AcquireNotificationMessages (ctx , database.AcquireNotificationMessagesParams {
138
139
Count : int32 (n .cfg .LeaseCount ),
139
140
MaxAttemptCount : int32 (n .cfg .MaxSendAttempts ),
140
- NotifierID : int32 ( n .id ) ,
141
+ NotifierID : n .id ,
141
142
LeaseSeconds : int32 (n .cfg .LeasePeriod .Value ().Seconds ()),
142
143
})
143
144
if err != nil {
0 commit comments