@@ -71,12 +71,18 @@ func (n *notifier) run(ctx context.Context, success chan<- dispatchResult, failu
71
71
default :
72
72
}
73
73
74
- // Check if notifier is paused.
75
-
76
- // Call process() immediately (i.e. don't wait an initial tick).
77
- err := n .process (ctx ,success ,failure )
74
+ // Check if notifier is not paused.
75
+ ok ,err := n .ensureRunning (ctx )
78
76
if err != nil {
79
- n .log .Error (ctx ,"failed to process messages" ,slog .Error (err ))
77
+ n .log .Error (ctx ,"failed to check notifier state" ,slog .Error (err ))
78
+ }
79
+
80
+ if ok {
81
+ // Call process() immediately (i.e. don't wait an initial tick).
82
+ err = n .process (ctx ,success ,failure )
83
+ if err != nil {
84
+ n .log .Error (ctx ,"failed to process messages" ,slog .Error (err ))
85
+ }
80
86
}
81
87
82
88
// Shortcut to bail out quickly if stop() has been called or the context canceled.
@@ -91,6 +97,25 @@ func (n *notifier) run(ctx context.Context, success chan<- dispatchResult, failu
91
97
}
92
98
}
93
99
100
+ // ensureRunning checks if notifier is not paused.
101
+ func (n * notifier )ensureRunning (ctx context.Context ) (bool ,error ) {
102
+ n .log .Debug (ctx ,"check if notifier is paused" )
103
+
104
+ settingsJSON ,err := n .store .GetNotificationsSettings (ctx )
105
+ if err != nil {
106
+ return false ,xerrors .Errorf ("get notifications settings: %w" ,err )
107
+ }
108
+
109
+ var settings codersdk.NotificationsSettings
110
+ if len (settingsJSON )> 0 {
111
+ err = json .Unmarshal ([]byte (settingsJSON ),& settings )
112
+ if err != nil {
113
+ return false ,xerrors .Errorf ("unmarshal notifications settings" )
114
+ }
115
+ }
116
+ return ! settings .NotifierPaused ,nil
117
+ }
118
+
94
119
// process is responsible for coordinating the retrieval, processing, and delivery of messages.
95
120
// Messages are dispatched concurrently, but they may block when success/failure channels are full.
96
121
//