Skip to content

Commit b08282a

Browse files
committed
fix: exclude prebuilt workspaces from template-level lifecycle updates
1 parent 155c7bb commit b08282a

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

coderd/database/queries.sql.go

Lines changed: 12 additions & 5 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: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,15 @@ WHERE
554554

555555
-- name: UpdateWorkspacesTTLByTemplateID :exec
556556
UPDATE
557-
workspaces
557+
workspaces
558558
SET
559-
ttl = $2
559+
ttl = $2
560560
WHERE
561-
template_id = $1;
561+
template_id = $1
562+
-- Prebuilt workspaces (identified by having the prebuilds system user as owner_id)
563+
-- should not have their TTL updated, as they are handled by the prebuilds
564+
-- reconciliation loop.
565+
AND workspaces.owner_id != 'c42fdf75-3097-471c-8c33-fb52454d81c0'::UUID;
562566

563567
-- name: UpdateWorkspaceLastUsedAt :exec
564568
UPDATE
@@ -805,8 +809,11 @@ SET
805809
dormant_at = CASE WHEN @dormant_at::timestamptz > '0001-01-01 00:00:00+00'::timestamptz THEN @dormant_at::timestamptz ELSE dormant_at END
806810
WHERE
807811
template_id = @template_id
808-
AND
809-
dormant_at IS NOT NULL
812+
AND dormant_at IS NOT NULL
813+
-- Prebuilt workspaces (identified by having the prebuilds system user as owner_id)
814+
-- should not have their dormant or deleting at set, as these are handled by the
815+
-- prebuilds reconciliation loop.
816+
AND workspaces.owner_id != 'c42fdf75-3097-471c-8c33-fb52454d81c0'::UUID
810817
RETURNING *;
811818

812819
-- name: UpdateTemplateWorkspacesLastUsedAt :exec

enterprise/coderd/schedule/template.go

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

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

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

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

0 commit comments

Comments
 (0)