Skip to content

fix: set prebuilds lifecycle parameters on creation and claim #19252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: remove template lifecycle update changes
  • Loading branch information
ssncferreira committed Aug 8, 2025
commit 2761b7e5526d7c062648d99c3c3873f0631c3c5d
11 changes: 2 additions & 9 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 3 additions & 10 deletions coderd/database/queries/workspaces.sql
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,7 @@ UPDATE
SET
ttl = $2
WHERE
template_id = $1
-- Prebuilt workspaces (identified by having the prebuilds system user as owner_id)
-- should not have their TTL updated, as they are handled by the prebuilds
-- reconciliation loop.
AND workspaces.owner_id != 'c42fdf75-3097-471c-8c33-fb52454d81c0'::UUID;
template_id = $1;

-- name: UpdateWorkspaceLastUsedAt :exec
UPDATE
Expand Down Expand Up @@ -821,11 +817,8 @@ SET
dormant_at = CASE WHEN @dormant_at::timestamptz > '0001-01-01 00:00:00+00'::timestamptz THEN @dormant_at::timestamptz ELSE dormant_at END
WHERE
template_id = @template_id
AND dormant_at IS NOT NULL
-- Prebuilt workspaces (identified by having the prebuilds system user as owner_id)
-- should not have their dormant or deleting at set, as these are handled by the
-- prebuilds reconciliation loop.
AND workspaces.owner_id != 'c42fdf75-3097-471c-8c33-fb52454d81c0'::UUID
AND
dormant_at IS NOT NULL
RETURNING *;

-- name: UpdateTemplateWorkspacesLastUsedAt :exec
Expand Down
11 changes: 1 addition & 10 deletions enterprise/coderd/schedule/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@ func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.S
nextStartAts := []time.Time{}

for _, workspace := range workspaces {
// Skip prebuilt workspaces
if workspace.IsPrebuild() {
continue
}
nextStartAt := time.Time{}
if workspace.AutostartSchedule.Valid {
next, err := agpl.NextAllowedAutostart(s.now(), workspace.AutostartSchedule.String, templateSchedule)
Expand All @@ -258,7 +254,7 @@ func (s *EnterpriseTemplateScheduleStore) Set(ctx context.Context, db database.S
nextStartAts = append(nextStartAts, nextStartAt)
}

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

// Skip lifecycle updates for prebuilt workspaces
if workspace.IsPrebuild() {
return nil
}

job, err := db.GetProvisionerJobByID(ctx, build.JobID)
if err != nil {
return xerrors.Errorf("get provisioner job %q: %w", build.JobID, err)
Expand Down
Loading