Skip to content

Commit 10fcd6e

Browse files
committed
fix: exclude prebuilt workspaces from template-level lifecycle updates
1 parent 92d505c commit 10fcd6e

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

coderd/database/queries.sql.go

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaces.sql

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,11 @@ UPDATE
570570
SET
571571
ttl = $2
572572
WHERE
573-
template_id = $1;
573+
template_id = $1
574+
-- Prebuilt workspaces (identified by having the prebuilds system user as owner_id)
575+
-- should not have their TTL updated, as they are handled by the prebuilds
576+
-- reconciliation loop.
577+
AND workspaces.owner_id != 'c42fdf75-3097-471c-8c33-fb52454d81c0'::UUID;
574578

575579
-- name: UpdateWorkspaceLastUsedAt :exec
576580
UPDATE
@@ -821,8 +825,11 @@ SET
821825
dormant_at = CASE WHEN @dormant_at::timestamptz > '0001-01-01 00:00:00+00'::timestamptz THEN @dormant_at::timestamptz ELSE dormant_at END
822826
WHERE
823827
template_id = @template_id
824-
AND
825-
dormant_at IS NOT NULL
828+
AND dormant_at IS NOT NULL
829+
-- Prebuilt workspaces (identified by having the prebuilds system user as owner_id)
830+
-- should not have their dormant or deleting at set, as these are handled by the
831+
-- prebuilds reconciliation loop.
832+
AND workspaces.owner_id != 'c42fdf75-3097-471c-8c33-fb52454d81c0'::UUID
826833
RETURNING *;
827834

828835
-- name: UpdateTemplateWorkspacesLastUsedAt :exec

enterprise/coderd/schedule/template.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.S
242242
nextStartAts := []time.Time{}
243243

244244
for _, workspace := range workspaces {
245+
// Skip prebuilt workspaces
246+
if workspace.IsPrebuild() {
247+
continue
248+
}
245249
nextStartAt := time.Time{}
246250
if workspace.AutostartSchedule.Valid {
247251
next, err := agpl.NextAllowedAutostart(s.now(), workspace.AutostartSchedule.String, templateSchedule)
@@ -254,7 +258,7 @@ func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.S
254258
nextStartAts = append(nextStartAts, nextStartAt)
255259
}
256260

257-
//nolint:gocritic // We need to be able to update information about all workspaces.
261+
//nolint:gocritic // We need to be able to update information about regular user workspaces.
258262
if err := db.BatchUpdateWorkspaceNextStartAt(dbauthz.AsSystemRestricted(ctx), database.BatchUpdateWorkspaceNextStartAtParams{
259263
IDs: workspaceIDs,
260264
NextStartAts: nextStartAts,
@@ -334,6 +338,11 @@ func (s *EnterpriseTemplateScheduleStore) updateWorkspaceBuild(ctx context.Conte
334338
return xerrors.Errorf("get workspace %q: %w", build.WorkspaceID, err)
335339
}
336340

341+
// Skip lifecycle updates for prebuilt workspaces
342+
if workspace.IsPrebuild() {
343+
return nil
344+
}
345+
337346
job, err := db.GetProvisionerJobByID(ctx, build.JobID)
338347
if err != nil {
339348
return xerrors.Errorf("get provisioner job %q: %w", build.JobID, err)

0 commit comments

Comments
 (0)