mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
Incorporate in-progress jobs into state calculation
Signed-off-by: Danny Kopping <danny@coder.com>
This commit is contained in:
@ -5414,25 +5414,35 @@ WITH
|
||||
INNER JOIN template_version_presets tvp ON tvp.template_version_id = tv.id
|
||||
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)
|
||||
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
|
||||
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
|
||||
WHERE pj.job_status NOT IN
|
||||
('succeeded'::provisioner_job_status, 'canceled'::provisioner_job_status,
|
||||
'failed'::provisioner_job_status))
|
||||
SELECT t.template_id,
|
||||
COUNT(p.id) AS actual, -- running prebuilds for active version
|
||||
MAX(CASE WHEN t.using_active_version THEN t.desired_instances ELSE 0 END) AS desired, -- we only care about the active version's desired instances
|
||||
SUM(CASE WHEN t.using_active_version THEN 0 ELSE 1 END) AS extraneous, -- running prebuilds for inactive version
|
||||
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
|
||||
FROM templates_with_prebuilds t
|
||||
LEFT JOIN running_prebuilds p ON p.template_version_id = t.template_version_id
|
||||
GROUP BY t.template_id, p.id, t.deleted, t.deprecated
|
||||
LEFT JOIN prebuilds_in_progress pip ON pip.template_version_id = t.template_version_id
|
||||
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 int64 `db:"actual" json:"actual"`
|
||||
Desired interface{} `db:"desired" json:"desired"`
|
||||
Extraneous int64 `db:"extraneous" json:"extraneous"`
|
||||
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"`
|
||||
InProgress int32 `db:"in_progress" json:"in_progress"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
Deprecated bool `db:"deprecated" json:"deprecated"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) GetTemplatePrebuildState(ctx context.Context, templateID uuid.UUID) ([]GetTemplatePrebuildStateRow, error) {
|
||||
@ -5449,6 +5459,7 @@ func (q *sqlQuerier) GetTemplatePrebuildState(ctx context.Context, templateID uu
|
||||
&i.Actual,
|
||||
&i.Desired,
|
||||
&i.Extraneous,
|
||||
&i.InProgress,
|
||||
&i.Deleted,
|
||||
&i.Deprecated,
|
||||
); err != nil {
|
||||
|
Reference in New Issue
Block a user