mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat: add auto-locking/deleting workspace based on template config (#8240)
This commit is contained in:
@ -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
|
||||
`
|
||||
|
Reference in New Issue
Block a user