feat: add provisioner job metadata (#16454)

This change adds metadata to provisioner jobs to help with rendering
related tempaltes and workspaces in the UI.

Updates #15084
This commit is contained in:
Mathias Fredriksson
2025-02-06 16:19:20 +02:00
committed by GitHub
parent 44d9f5ff4e
commit b04d883348
18 changed files with 666 additions and 167 deletions

View File

@ -130,13 +130,29 @@ SELECT
AND pj.organization_id = pd.organization_id
AND pj.provisioner = ANY(pd.provisioners)
AND provisioner_tagset_contains(pd.tags, pj.tags)
) AS available_workers
) AS available_workers,
-- Include template and workspace information.
COALESCE(tv.name, '') AS template_version_name,
t.id AS template_id,
COALESCE(t.name, '') AS template_name,
COALESCE(t.display_name, '') AS template_display_name,
w.id AS workspace_id,
COALESCE(w.name, '') AS workspace_name
FROM
provisioner_jobs pj
LEFT JOIN
queue_position qp ON qp.id = pj.id
LEFT JOIN
queue_size qs ON TRUE
LEFT JOIN
workspace_builds wb ON wb.id = CASE WHEN pj.input ? 'workspace_build_id' THEN (pj.input->>'workspace_build_id')::uuid END
LEFT JOIN
workspaces w ON wb.workspace_id = w.id
LEFT JOIN
-- We should always have a template version, either explicitly or implicitly via workspace build.
template_versions tv ON tv.id = CASE WHEN pj.input ? 'template_version_id' THEN (pj.input->>'template_version_id')::uuid ELSE wb.template_version_id END
LEFT JOIN
templates t ON tv.template_id = t.id
WHERE
(sqlc.narg('organization_id')::uuid IS NULL OR pj.organization_id = @organization_id)
AND (COALESCE(array_length(@ids::uuid[], 1), 0) = 0 OR pj.id = ANY(@ids::uuid[]))
@ -144,7 +160,13 @@ WHERE
GROUP BY
pj.id,
qp.queue_position,
qs.count
qs.count,
tv.name,
t.id,
t.name,
t.display_name,
w.id,
w.name
ORDER BY
pj.created_at DESC
LIMIT