mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
Very basic prebuild reassignment
Signed-off-by: Danny Kopping <danny@coder.com>
This commit is contained in:
@ -62,3 +62,18 @@ FROM templates_with_prebuilds t
|
||||
LEFT JOIN prebuilds_in_progress pip ON pip.template_version_id = t.template_version_id
|
||||
GROUP BY t.using_active_version, t.template_id, t.template_version_id, p.count, p.ids,
|
||||
p.template_version_id, t.deleted, t.deprecated;
|
||||
|
||||
-- name: ClaimPrebuild :one
|
||||
UPDATE workspaces w
|
||||
SET owner_id = @new_owner_id::uuid, updated_at = NOW() -- TODO: annoying; having two input params breaks dbgen
|
||||
WHERE w.id IN (SELECT p.id
|
||||
FROM workspace_prebuilds p
|
||||
INNER JOIN workspace_latest_build b ON b.workspace_id = p.id
|
||||
INNER JOIN provisioner_jobs pj ON b.job_id = pj.id
|
||||
INNER JOIN templates t ON p.template_id = t.id
|
||||
WHERE (b.transition = 'start'::workspace_transition
|
||||
AND pj.job_status IN ('succeeded'::provisioner_job_status))
|
||||
AND b.template_version_id = t.active_version_id
|
||||
ORDER BY random()
|
||||
LIMIT 1 FOR UPDATE OF p SKIP LOCKED)
|
||||
RETURNING w.id;
|
||||
|
Reference in New Issue
Block a user