diff --git a/cli/server.go b/cli/server.go index b9abe82b47..66cc220864 100644 --- a/cli/server.go +++ b/cli/server.go @@ -70,7 +70,6 @@ import ( "github.com/coder/coder/v2/coderd/database/migrations" "github.com/coder/coder/v2/coderd/database/pubsub" "github.com/coder/coder/v2/coderd/devtunnel" - "github.com/coder/coder/v2/coderd/dormancy" "github.com/coder/coder/v2/coderd/gitauth" "github.com/coder/coder/v2/coderd/gitsshkey" "github.com/coder/coder/v2/coderd/httpapi" @@ -866,9 +865,6 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd. options.StatsBatcher = batcher defer closeBatcher() - closeCheckInactiveUsersFunc := dormancy.CheckInactiveUsers(ctx, logger, options.Database) - defer closeCheckInactiveUsersFunc() - // We use a separate coderAPICloser so the Enterprise API // can have it's own close functions. This is cleaner // than abstracting the Coder API itself. diff --git a/enterprise/cli/server.go b/enterprise/cli/server.go index 197eab61e1..0918c07226 100644 --- a/enterprise/cli/server.go +++ b/enterprise/cli/server.go @@ -18,6 +18,7 @@ import ( "github.com/coder/coder/v2/enterprise/audit" "github.com/coder/coder/v2/enterprise/audit/backends" "github.com/coder/coder/v2/enterprise/coderd" + "github.com/coder/coder/v2/enterprise/coderd/dormancy" "github.com/coder/coder/v2/enterprise/trialer" "github.com/coder/coder/v2/tailnet" @@ -67,6 +68,8 @@ func (r *RootCmd) server() *clibase.Cmd { ProxyHealthInterval: options.DeploymentValues.ProxyHealthStatusInterval.Value(), DefaultQuietHoursSchedule: options.DeploymentValues.UserQuietHoursSchedule.DefaultSchedule.Value(), ProvisionerDaemonPSK: options.DeploymentValues.Provisioner.DaemonPSK.Value(), + + CheckInactiveUsersCancelFunc: dormancy.CheckInactiveUsers(ctx, options.Logger, options.Database), } api, err := coderd.New(ctx, o) diff --git a/enterprise/coderd/coderd.go b/enterprise/coderd/coderd.go index 7943c701de..1bc0815cd5 100644 --- a/enterprise/coderd/coderd.go +++ b/enterprise/coderd/coderd.go @@ -378,6 +378,8 @@ type Options struct { // optional pre-shared key for authentication of external provisioner daemons ProvisionerDaemonPSK string + + CheckInactiveUsersCancelFunc func() } type API struct { @@ -414,6 +416,10 @@ func (api *API) Close() error { if api.derpMesh != nil { _ = api.derpMesh.Close() } + + if api.Options.CheckInactiveUsersCancelFunc != nil { + api.Options.CheckInactiveUsersCancelFunc() + } return api.AGPL.Close() } diff --git a/coderd/dormancy/dormantusersjob.go b/enterprise/coderd/dormancy/dormantusersjob.go similarity index 100% rename from coderd/dormancy/dormantusersjob.go rename to enterprise/coderd/dormancy/dormantusersjob.go diff --git a/coderd/dormancy/dormantusersjob_test.go b/enterprise/coderd/dormancy/dormantusersjob_test.go similarity index 98% rename from coderd/dormancy/dormantusersjob_test.go rename to enterprise/coderd/dormancy/dormantusersjob_test.go index f937589faa..a20c860917 100644 --- a/coderd/dormancy/dormantusersjob_test.go +++ b/enterprise/coderd/dormancy/dormantusersjob_test.go @@ -13,7 +13,7 @@ import ( "github.com/coder/coder/v2/coderd/database" "github.com/coder/coder/v2/coderd/database/dbfake" - "github.com/coder/coder/v2/coderd/dormancy" + "github.com/coder/coder/v2/enterprise/coderd/dormancy" "github.com/coder/coder/v2/testutil" )