@@ -56,15 +56,16 @@ import (
56
56
57
57
"cdr.dev/slog"
58
58
"cdr.dev/slog/sloggers/sloghuman"
59
- "github.com/coder/coder/v2/coderd/entitlements"
60
- "github.com/coder/coder/v2/coderd/notifications/reports"
61
- "github.com/coder/coder/v2/coderd/runtimeconfig"
62
59
"github.com/coder/pretty"
63
60
"github.com/coder/quartz"
64
61
"github.com/coder/retry"
65
62
"github.com/coder/serpent"
66
63
"github.com/coder/wgtunnel/tunnelsdk"
67
64
65
+ "github.com/coder/coder/v2/coderd/entitlements"
66
+ "github.com/coder/coder/v2/coderd/notifications/reports"
67
+ "github.com/coder/coder/v2/coderd/runtimeconfig"
68
+
68
69
"github.com/coder/coder/v2/buildinfo"
69
70
"github.com/coder/coder/v2/cli/clilog"
70
71
"github.com/coder/coder/v2/cli/cliui"
@@ -684,10 +685,6 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
684
685
options .OIDCConfig = oc
685
686
}
686
687
687
- experiments := coderd .ReadExperiments (
688
- options .Logger , options .DeploymentValues .Experiments .Value (),
689
- )
690
-
691
688
// We'll read from this channel in the select below that tracks shutdown. If it remains
692
689
// nil, that case of the select will just never fire, but it's important not to have a
693
690
// "bare" read on this channel.
@@ -951,6 +948,33 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
951
948
return xerrors .Errorf ("write config url: %w" , err )
952
949
}
953
950
951
+ // Manage notifications.
952
+ cfg := options .DeploymentValues .Notifications
953
+ metrics := notifications .NewMetrics (options .PrometheusRegistry )
954
+ helpers := templateHelpers (options )
955
+
956
+ // The enqueuer is responsible for enqueueing notifications to the given store.
957
+ enqueuer , err := notifications .NewStoreEnqueuer (cfg , options .Database , helpers , logger .Named ("notifications.enqueuer" ), quartz .NewReal ())
958
+ if err != nil {
959
+ return xerrors .Errorf ("failed to instantiate notification store enqueuer: %w" , err )
960
+ }
961
+ options .NotificationsEnqueuer = enqueuer
962
+
963
+ // The notification manager is responsible for:
964
+ // - creating notifiers and managing their lifecycles (notifiers are responsible for dequeueing/sending notifications)
965
+ // - keeping the store updated with status updates
966
+ notificationsManager , err := notifications .NewManager (cfg , options .Database , helpers , metrics , logger .Named ("notifications.manager" ))
967
+ if err != nil {
968
+ return xerrors .Errorf ("failed to instantiate notification manager: %w" , err )
969
+ }
970
+
971
+ // nolint:gocritic // TODO: create own role.
972
+ notificationsManager .Run (dbauthz .AsSystemRestricted (ctx ))
973
+
974
+ // Run report generator to distribute periodic reports.
975
+ notificationReportGenerator := reports .NewReportGenerator (ctx , logger .Named ("notifications.report_generator" ), options .Database , options .NotificationsEnqueuer , quartz .NewReal ())
976
+ defer notificationReportGenerator .Close ()
977
+
954
978
// Since errCh only has one buffered slot, all routines
955
979
// sending on it must be wrapped in a select/default to
956
980
// avoid leaving dangling goroutines waiting for the
@@ -1007,38 +1031,6 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
1007
1031
options .WorkspaceUsageTracker = tracker
1008
1032
defer tracker .Close ()
1009
1033
1010
- // Manage notifications.
1011
- var (
1012
- notificationsManager * notifications.Manager
1013
- )
1014
- if experiments .Enabled (codersdk .ExperimentNotifications ) {
1015
- cfg := options .DeploymentValues .Notifications
1016
- metrics := notifications .NewMetrics (options .PrometheusRegistry )
1017
- helpers := templateHelpers (options )
1018
-
1019
- // The enqueuer is responsible for enqueueing notifications to the given store.
1020
- enqueuer , err := notifications .NewStoreEnqueuer (cfg , options .Database , helpers , logger .Named ("notifications.enqueuer" ), quartz .NewReal ())
1021
- if err != nil {
1022
- return xerrors .Errorf ("failed to instantiate notification store enqueuer: %w" , err )
1023
- }
1024
- options .NotificationsEnqueuer = enqueuer
1025
-
1026
- // The notification manager is responsible for:
1027
- // - creating notifiers and managing their lifecycles (notifiers are responsible for dequeueing/sending notifications)
1028
- // - keeping the store updated with status updates
1029
- notificationsManager , err = notifications .NewManager (cfg , options .Database , helpers , metrics , logger .Named ("notifications.manager" ))
1030
- if err != nil {
1031
- return xerrors .Errorf ("failed to instantiate notification manager: %w" , err )
1032
- }
1033
-
1034
- // nolint:gocritic // TODO: create own role.
1035
- notificationsManager .Run (dbauthz .AsSystemRestricted (ctx ))
1036
-
1037
- // Run report generator to distribute periodic reports.
1038
- notificationReportGenerator := reports .NewReportGenerator (ctx , logger .Named ("notifications.report_generator" ), options .Database , options .NotificationsEnqueuer , quartz .NewReal ())
1039
- defer notificationReportGenerator .Close ()
1040
- }
1041
-
1042
1034
// Wrap the server in middleware that redirects to the access URL if
1043
1035
// the request is not to a local IP.
1044
1036
var handler http.Handler = coderAPI .RootHandler
@@ -1158,19 +1150,17 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
1158
1150
// Cancel any remaining in-flight requests.
1159
1151
shutdownConns ()
1160
1152
1161
- if notificationsManager != nil {
1162
- // Stop the notification manager, which will cause any buffered updates to the store to be flushed.
1163
- // If the Stop() call times out, messages that were sent but not reflected as such in the store will have
1164
- // their leases expire after a period of time and will be re-queued for sending.
1165
- // See CODER_NOTIFICATIONS_LEASE_PERIOD.
1166
- cliui .Info (inv .Stdout , "Shutting down notifications manager..." + "\n " )
1167
- err = shutdownWithTimeout (notificationsManager .Stop , 5 * time .Second )
1168
- if err != nil {
1169
- cliui .Warnf (inv .Stderr , "Notifications manager shutdown took longer than 5s, " +
1170
- "this may result in duplicate notifications being sent: %s\n " , err )
1171
- } else {
1172
- cliui .Info (inv .Stdout , "Gracefully shut down notifications manager\n " )
1173
- }
1153
+ // Stop the notification manager, which will cause any buffered updates to the store to be flushed.
1154
+ // If the Stop() call times out, messages that were sent but not reflected as such in the store will have
1155
+ // their leases expire after a period of time and will be re-queued for sending.
1156
+ // See CODER_NOTIFICATIONS_LEASE_PERIOD.
1157
+ cliui .Info (inv .Stdout , "Shutting down notifications manager..." + "\n " )
1158
+ err = shutdownWithTimeout (notificationsManager .Stop , 5 * time .Second )
1159
+ if err != nil {
1160
+ cliui .Warnf (inv .Stderr , "Notifications manager shutdown took longer than 5s, " +
1161
+ "this may result in duplicate notifications being sent: %s\n " , err )
1162
+ } else {
1163
+ cliui .Info (inv .Stdout , "Gracefully shut down notifications manager\n " )
1174
1164
}
1175
1165
1176
1166
// Shut down provisioners before waiting for WebSockets
0 commit comments