@@ -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"
@@ -679,10 +680,6 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
679
680
options .OIDCConfig = oc
680
681
}
681
682
682
- experiments := coderd .ReadExperiments (
683
- options .Logger , options .DeploymentValues .Experiments .Value (),
684
- )
685
-
686
683
// We'll read from this channel in the select below that tracks shutdown. If it remains
687
684
// nil, that case of the select will just never fire, but it's important not to have a
688
685
// "bare" read on this channel.
@@ -946,6 +943,33 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
946
943
return xerrors .Errorf ("write config url: %w" , err )
947
944
}
948
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
+
949
973
// Since errCh only has one buffered slot, all routines
950
974
// sending on it must be wrapped in a select/default to
951
975
// avoid leaving dangling goroutines waiting for the
@@ -1002,38 +1026,6 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
1002
1026
options .WorkspaceUsageTracker = tracker
1003
1027
defer tracker .Close ()
1004
1028
1005
- // Manage notifications.
1006
- var (
1007
- notificationsManager * notifications.Manager
1008
- )
1009
- if experiments .Enabled (codersdk .ExperimentNotifications ) {
1010
- cfg := options .DeploymentValues .Notifications
1011
- metrics := notifications .NewMetrics (options .PrometheusRegistry )
1012
- helpers := templateHelpers (options )
1013
-
1014
- // The enqueuer is responsible for enqueueing notifications to the given store.
1015
- enqueuer , err := notifications .NewStoreEnqueuer (cfg , options .Database , helpers , logger .Named ("notifications.enqueuer" ), quartz .NewReal ())
1016
- if err != nil {
1017
- return xerrors .Errorf ("failed to instantiate notification store enqueuer: %w" , err )
1018
- }
1019
- options .NotificationsEnqueuer = enqueuer
1020
-
1021
- // The notification manager is responsible for:
1022
- // - creating notifiers and managing their lifecycles (notifiers are responsible for dequeueing/sending notifications)
1023
- // - keeping the store updated with status updates
1024
- notificationsManager , err = notifications .NewManager (cfg , options .Database , helpers , metrics , logger .Named ("notifications.manager" ))
1025
- if err != nil {
1026
- return xerrors .Errorf ("failed to instantiate notification manager: %w" , err )
1027
- }
1028
-
1029
- // nolint:gocritic // TODO: create own role.
1030
- notificationsManager .Run (dbauthz .AsSystemRestricted (ctx ))
1031
-
1032
- // Run report generator to distribute periodic reports.
1033
- notificationReportGenerator := reports .NewReportGenerator (ctx , logger .Named ("notifications.report_generator" ), options .Database , options .NotificationsEnqueuer , quartz .NewReal ())
1034
- defer notificationReportGenerator .Close ()
1035
- }
1036
-
1037
1029
// Wrap the server in middleware that redirects to the access URL if
1038
1030
// the request is not to a local IP.
1039
1031
var handler http.Handler = coderAPI .RootHandler
@@ -1153,19 +1145,17 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
1153
1145
// Cancel any remaining in-flight requests.
1154
1146
shutdownConns ()
1155
1147
1156
- if notificationsManager != nil {
1157
- // Stop the notification manager, which will cause any buffered updates to the store to be flushed.
1158
- // If the Stop() call times out, messages that were sent but not reflected as such in the store will have
1159
- // their leases expire after a period of time and will be re-queued for sending.
1160
- // See CODER_NOTIFICATIONS_LEASE_PERIOD.
1161
- cliui .Info (inv .Stdout , "Shutting down notifications manager..." + "\n " )
1162
- err = shutdownWithTimeout (notificationsManager .Stop , 5 * time .Second )
1163
- if err != nil {
1164
- cliui .Warnf (inv .Stderr , "Notifications manager shutdown took longer than 5s, " +
1165
- "this may result in duplicate notifications being sent: %s\n " , err )
1166
- } else {
1167
- cliui .Info (inv .Stdout , "Gracefully shut down notifications manager\n " )
1168
- }
1148
+ // Stop the notification manager, which will cause any buffered updates to the store to be flushed.
1149
+ // If the Stop() call times out, messages that were sent but not reflected as such in the store will have
1150
+ // their leases expire after a period of time and will be re-queued for sending.
1151
+ // See CODER_NOTIFICATIONS_LEASE_PERIOD.
1152
+ cliui .Info (inv .Stdout , "Shutting down notifications manager..." + "\n " )
1153
+ err = shutdownWithTimeout (notificationsManager .Stop , 5 * time .Second )
1154
+ if err != nil {
1155
+ cliui .Warnf (inv .Stderr , "Notifications manager shutdown took longer than 5s, " +
1156
+ "this may result in duplicate notifications being sent: %s\n " , err )
1157
+ } else {
1158
+ cliui .Info (inv .Stdout , "Gracefully shut down notifications manager\n " )
1169
1159
}
1170
1160
1171
1161
// Shut down provisioners before waiting for WebSockets
0 commit comments