mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
@ -5415,7 +5415,7 @@ WITH
|
||||
INNER JOIN template_version_preset_prebuilds tvpp ON tvpp.preset_id = tvp.id
|
||||
WHERE t.id = $1::uuid
|
||||
GROUP BY t.id, tv.id, tvpp.id),
|
||||
prebuilds_in_progress AS (SELECT wpb.template_version_id, pj.id AS job_id, pj.type, pj.job_status
|
||||
prebuilds_in_progress AS (SELECT wpb.template_version_id, pj.id AS job_id, pj.type, pj.job_status, wpb.transition
|
||||
FROM workspace_prebuild_builds wpb
|
||||
INNER JOIN workspace_latest_build wlb ON wpb.workspace_id = wlb.workspace_id
|
||||
INNER JOIN provisioner_jobs pj ON wlb.job_id = pj.id
|
||||
@ -5423,12 +5423,17 @@ WITH
|
||||
('succeeded'::provisioner_job_status, 'canceled'::provisioner_job_status,
|
||||
'failed'::provisioner_job_status))
|
||||
SELECT t.template_id,
|
||||
CAST(COUNT(p.id) AS INT) AS actual, -- running prebuilds for active version
|
||||
CAST(MAX(CASE WHEN t.using_active_version THEN t.desired_instances ELSE 0 END) AS int) AS desired, -- we only care about the active version's desired instances
|
||||
CAST(SUM(CASE WHEN t.using_active_version THEN 0 ELSE 1 END) AS INT) AS extraneous, -- running prebuilds for inactive version
|
||||
CAST(COUNT(pip.template_version_id) AS INT) AS in_progress,
|
||||
t.deleted,
|
||||
t.deprecated
|
||||
CAST(COUNT(p.id) AS INT) AS actual, -- running prebuilds for active version
|
||||
CAST(MAX(CASE WHEN t.using_active_version THEN t.desired_instances ELSE 0 END) AS int) AS desired, -- we only care about the active version's desired instances
|
||||
CAST(SUM(CASE WHEN t.using_active_version THEN 0 ELSE 1 END) AS INT) AS extraneous, -- running prebuilds for inactive version
|
||||
CAST(SUM(CASE
|
||||
WHEN pip.transition = 'start'::workspace_transition THEN 1
|
||||
ELSE 0 END) AS INT) AS starting,
|
||||
CAST(SUM(CASE
|
||||
WHEN pip.transition = 'delete'::workspace_transition THEN 1
|
||||
ELSE 0 END) AS INT) AS deleting,
|
||||
t.deleted AS template_deleted,
|
||||
t.deprecated AS template_deprecated
|
||||
FROM templates_with_prebuilds t
|
||||
LEFT JOIN running_prebuilds p ON p.template_version_id = t.template_version_id
|
||||
LEFT JOIN prebuilds_in_progress pip ON pip.template_version_id = t.template_version_id
|
||||
@ -5436,13 +5441,14 @@ GROUP BY t.template_id, p.id, t.deleted, t.deprecated, pip.template_version_id
|
||||
`
|
||||
|
||||
type GetTemplatePrebuildStateRow struct {
|
||||
TemplateID uuid.UUID `db:"template_id" json:"template_id"`
|
||||
Actual int32 `db:"actual" json:"actual"`
|
||||
Desired int32 `db:"desired" json:"desired"`
|
||||
Extraneous int32 `db:"extraneous" json:"extraneous"`
|
||||
InProgress int32 `db:"in_progress" json:"in_progress"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Deprecated bool `db:"deprecated" json:"deprecated"`
|
||||
TemplateID uuid.UUID `db:"template_id" json:"template_id"`
|
||||
Actual int32 `db:"actual" json:"actual"`
|
||||
Desired int32 `db:"desired" json:"desired"`
|
||||
Extraneous int32 `db:"extraneous" json:"extraneous"`
|
||||
Starting int32 `db:"starting" json:"starting"`
|
||||
Deleting int32 `db:"deleting" json:"deleting"`
|
||||
TemplateDeleted bool `db:"template_deleted" json:"template_deleted"`
|
||||
TemplateDeprecated bool `db:"template_deprecated" json:"template_deprecated"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) GetTemplatePrebuildState(ctx context.Context, templateID uuid.UUID) ([]GetTemplatePrebuildStateRow, error) {
|
||||
@ -5459,9 +5465,10 @@ func (q *sqlQuerier) GetTemplatePrebuildState(ctx context.Context, templateID uu
|
||||
&i.Actual,
|
||||
&i.Desired,
|
||||
&i.Extraneous,
|
||||
&i.InProgress,
|
||||
&i.Deleted,
|
||||
&i.Deprecated,
|
||||
&i.Starting,
|
||||
&i.Deleting,
|
||||
&i.TemplateDeleted,
|
||||
&i.TemplateDeprecated,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ WITH
|
||||
INNER JOIN template_version_preset_prebuilds tvpp ON tvpp.preset_id = tvp.id
|
||||
WHERE t.id = @template_id::uuid
|
||||
GROUP BY t.id, tv.id, tvpp.id),
|
||||
prebuilds_in_progress AS (SELECT wpb.template_version_id, pj.id AS job_id, pj.type, pj.job_status
|
||||
prebuilds_in_progress AS (SELECT wpb.template_version_id, pj.id AS job_id, pj.type, pj.job_status, wpb.transition
|
||||
FROM workspace_prebuild_builds wpb
|
||||
INNER JOIN workspace_latest_build wlb ON wpb.workspace_id = wlb.workspace_id
|
||||
INNER JOIN provisioner_jobs pj ON wlb.job_id = pj.id
|
||||
@ -26,12 +26,17 @@ WITH
|
||||
('succeeded'::provisioner_job_status, 'canceled'::provisioner_job_status,
|
||||
'failed'::provisioner_job_status))
|
||||
SELECT t.template_id,
|
||||
CAST(COUNT(p.id) AS INT) AS actual, -- running prebuilds for active version
|
||||
CAST(MAX(CASE WHEN t.using_active_version THEN t.desired_instances ELSE 0 END) AS int) AS desired, -- we only care about the active version's desired instances
|
||||
CAST(SUM(CASE WHEN t.using_active_version THEN 0 ELSE 1 END) AS INT) AS extraneous, -- running prebuilds for inactive version
|
||||
CAST(COUNT(pip.template_version_id) AS INT) AS in_progress,
|
||||
t.deleted,
|
||||
t.deprecated
|
||||
CAST(COUNT(p.id) AS INT) AS actual, -- running prebuilds for active version
|
||||
CAST(MAX(CASE WHEN t.using_active_version THEN t.desired_instances ELSE 0 END) AS int) AS desired, -- we only care about the active version's desired instances
|
||||
CAST(SUM(CASE WHEN t.using_active_version THEN 0 ELSE 1 END) AS INT) AS extraneous, -- running prebuilds for inactive version
|
||||
CAST(SUM(CASE
|
||||
WHEN pip.transition = 'start'::workspace_transition THEN 1
|
||||
ELSE 0 END) AS INT) AS starting,
|
||||
CAST(SUM(CASE
|
||||
WHEN pip.transition = 'delete'::workspace_transition THEN 1
|
||||
ELSE 0 END) AS INT) AS deleting,
|
||||
t.deleted AS template_deleted,
|
||||
t.deprecated AS template_deprecated
|
||||
FROM templates_with_prebuilds t
|
||||
LEFT JOIN running_prebuilds p ON p.template_version_id = t.template_version_id
|
||||
LEFT JOIN prebuilds_in_progress pip ON pip.template_version_id = t.template_version_id
|
||||
|
Reference in New Issue
Block a user