Skip to content

Commit d60b9cb

Browse files
committed
reduce diff size
1 parent 21cad84 commit d60b9cb

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

cli/server.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,37 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
928928
options.StatsBatcher = batcher
929929
defer closeBatcher()
930930

931+
// Manage notifications.
932+
var (
933+
notificationsCfg = options.DeploymentValues.Notifications
934+
notificationsManager *notifications.Manager
935+
)
936+
937+
metrics := notifications.NewMetrics(options.PrometheusRegistry)
938+
helpers := templateHelpers(options)
939+
940+
// The enqueuer is responsible for enqueueing notifications to the given store.
941+
enqueuer, err := notifications.NewStoreEnqueuer(notificationsCfg, options.Database, options.Pubsub, helpers, logger.Named("notifications.enqueuer"), quartz.NewReal())
942+
if err != nil {
943+
return xerrors.Errorf("failed to instantiate notification store enqueuer: %w", err)
944+
}
945+
options.NotificationsEnqueuer = enqueuer
946+
947+
// The notification manager is responsible for:
948+
// - creating notifiers and managing their lifecycles (notifiers are responsible for dequeueing/sending notifications)
949+
// - keeping the store updated with status updates
950+
notificationsManager, err = notifications.NewManager(notificationsCfg, options.Database, options.Pubsub, helpers, metrics, logger.Named("notifications.manager"))
951+
if err != nil {
952+
return xerrors.Errorf("failed to instantiate notification manager: %w", err)
953+
}
954+
955+
// nolint:gocritic // We need to run the manager in a notifier context.
956+
notificationsManager.Run(dbauthz.AsNotifier(ctx))
957+
958+
// Run report generator to distribute periodic reports.
959+
notificationReportGenerator := reports.NewReportGenerator(ctx, logger.Named("notifications.report_generator"), options.Database, options.NotificationsEnqueuer, quartz.NewReal())
960+
defer notificationReportGenerator.Close()
961+
931962
// We use a separate coderAPICloser so the Enterprise API
932963
// can have its own close functions. This is cleaner
933964
// than abstracting the Coder API itself.
@@ -975,37 +1006,6 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
9751006
return xerrors.Errorf("write config url: %w", err)
9761007
}
9771008

978-
// Manage notifications.
979-
var (
980-
notificationsCfg = options.DeploymentValues.Notifications
981-
notificationsManager *notifications.Manager
982-
)
983-
984-
metrics := notifications.NewMetrics(options.PrometheusRegistry)
985-
helpers := templateHelpers(options)
986-
987-
// The enqueuer is responsible for enqueueing notifications to the given store.
988-
enqueuer, err := notifications.NewStoreEnqueuer(notificationsCfg, options.Database, options.Pubsub, helpers, logger.Named("notifications.enqueuer"), quartz.NewReal())
989-
if err != nil {
990-
return xerrors.Errorf("failed to instantiate notification store enqueuer: %w", err)
991-
}
992-
options.NotificationsEnqueuer = enqueuer
993-
994-
// The notification manager is responsible for:
995-
// - creating notifiers and managing their lifecycles (notifiers are responsible for dequeueing/sending notifications)
996-
// - keeping the store updated with status updates
997-
notificationsManager, err = notifications.NewManager(notificationsCfg, options.Database, options.Pubsub, helpers, metrics, logger.Named("notifications.manager"))
998-
if err != nil {
999-
return xerrors.Errorf("failed to instantiate notification manager: %w", err)
1000-
}
1001-
1002-
// nolint:gocritic // We need to run the manager in a notifier context.
1003-
notificationsManager.Run(dbauthz.AsNotifier(ctx))
1004-
1005-
// Run report generator to distribute periodic reports.
1006-
notificationReportGenerator := reports.NewReportGenerator(ctx, logger.Named("notifications.report_generator"), options.Database, options.NotificationsEnqueuer, quartz.NewReal())
1007-
defer notificationReportGenerator.Close()
1008-
10091009
// Since errCh only has one buffered slot, all routines
10101010
// sending on it must be wrapped in a select/default to
10111011
// avoid leaving dangling goroutines waiting for the

0 commit comments

Comments
 (0)