@@ -943,6 +943,33 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
943
943
return xerrors .Errorf ("write config url: %w" , err )
944
944
}
945
945
946
+ // Manage notifications.
947
+ cfg := options .DeploymentValues .Notifications
948
+ metrics := notifications .NewMetrics (options .PrometheusRegistry )
949
+ helpers := templateHelpers (options )
950
+
951
+ // The enqueuer is responsible for enqueueing notifications to the given store.
952
+ enqueuer , err := notifications .NewStoreEnqueuer (cfg , options .Database , helpers , logger .Named ("notifications.enqueuer" ), quartz .NewReal ())
953
+ if err != nil {
954
+ return xerrors .Errorf ("failed to instantiate notification store enqueuer: %w" , err )
955
+ }
956
+ options .NotificationsEnqueuer = enqueuer
957
+
958
+ // The notification manager is responsible for:
959
+ // - creating notifiers and managing their lifecycles (notifiers are responsible for dequeueing/sending notifications)
960
+ // - keeping the store updated with status updates
961
+ notificationsManager , err := notifications .NewManager (cfg , options .Database , helpers , metrics , logger .Named ("notifications.manager" ))
962
+ if err != nil {
963
+ return xerrors .Errorf ("failed to instantiate notification manager: %w" , err )
964
+ }
965
+
966
+ // nolint:gocritic // TODO: create own role.
967
+ notificationsManager .Run (dbauthz .AsSystemRestricted (ctx ))
968
+
969
+ // Run report generator to distribute periodic reports.
970
+ notificationReportGenerator := reports .NewReportGenerator (ctx , logger .Named ("notifications.report_generator" ), options .Database , options .NotificationsEnqueuer , quartz .NewReal ())
971
+ defer notificationReportGenerator .Close ()
972
+
946
973
// Since errCh only has one buffered slot, all routines
947
974
// sending on it must be wrapped in a select/default to
948
975
// avoid leaving dangling goroutines waiting for the
@@ -999,33 +1026,6 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
999
1026
options .WorkspaceUsageTracker = tracker
1000
1027
defer tracker .Close ()
1001
1028
1002
- // Manage notifications.
1003
- cfg := options .DeploymentValues .Notifications
1004
- metrics := notifications .NewMetrics (options .PrometheusRegistry )
1005
- helpers := templateHelpers (options )
1006
-
1007
- // The enqueuer is responsible for enqueueing notifications to the given store.
1008
- enqueuer , err := notifications .NewStoreEnqueuer (cfg , options .Database , helpers , logger .Named ("notifications.enqueuer" ), quartz .NewReal ())
1009
- if err != nil {
1010
- return xerrors .Errorf ("failed to instantiate notification store enqueuer: %w" , err )
1011
- }
1012
- options .NotificationsEnqueuer = enqueuer
1013
-
1014
- // The notification manager is responsible for:
1015
- // - creating notifiers and managing their lifecycles (notifiers are responsible for dequeueing/sending notifications)
1016
- // - keeping the store updated with status updates
1017
- notificationsManager , err := notifications .NewManager (cfg , options .Database , helpers , metrics , logger .Named ("notifications.manager" ))
1018
- if err != nil {
1019
- return xerrors .Errorf ("failed to instantiate notification manager: %w" , err )
1020
- }
1021
-
1022
- // nolint:gocritic // TODO: create own role.
1023
- notificationsManager .Run (dbauthz .AsSystemRestricted (ctx ))
1024
-
1025
- // Run report generator to distribute periodic reports.
1026
- notificationReportGenerator := reports .NewReportGenerator (ctx , logger .Named ("notifications.report_generator" ), options .Database , options .NotificationsEnqueuer , quartz .NewReal ())
1027
- defer notificationReportGenerator .Close ()
1028
-
1029
1029
// Wrap the server in middleware that redirects to the access URL if
1030
1030
// the request is not to a local IP.
1031
1031
var handler http.Handler = coderAPI .RootHandler
0 commit comments