feat: add auto-locking/deleting workspace based on template config (#8240)

This commit is contained in:
Jon Ayers
2023-07-02 21:29:52 -05:00
committed by GitHub
parent 818c4a7f23
commit 4a9c8f407a
18 changed files with 726 additions and 70 deletions

View File

@ -8663,6 +8663,8 @@ LEFT JOIN
workspace_builds ON workspace_builds.workspace_id = workspaces.id
INNER JOIN
provisioner_jobs ON workspace_builds.job_id = provisioner_jobs.id
INNER JOIN
templates ON workspaces.template_id = templates.id
WHERE
workspace_builds.build_number = (
SELECT
@ -8700,6 +8702,20 @@ WHERE
provisioner_jobs.error IS NOT NULL AND
provisioner_jobs.error != '' AND
workspace_builds.transition = 'start'::workspace_transition
) OR
-- If the workspace's template has an inactivity_ttl set
-- it may be eligible for locking.
(
templates.inactivity_ttl > 0 AND
workspaces.locked_at IS NULL
) OR
-- If the workspace's template has a locked_ttl set
-- and the workspace is already locked
(
templates.locked_ttl > 0 AND
workspaces.locked_at IS NOT NULL
)
) AND workspaces.deleted = 'false'
`
@ -8899,7 +8915,8 @@ const updateWorkspaceLockedAt = `-- name: UpdateWorkspaceLockedAt :exec
UPDATE
workspaces
SET
locked_at = $2
locked_at = $2,
last_used_at = now() at time zone 'utc'
WHERE
id = $1
`