@@ -50,11 +50,12 @@ FROM workspace_latest_builds wlb
50
50
WHERE wlb .job_status IN (' pending' ::provisioner_job_status, ' running' ::provisioner_job_status)
51
51
GROUP BY t .id , wpb .template_version_id , wpb .transition ;
52
52
53
- -- GetPresetsBackoff groups workspace builds by template version ID.
53
+ -- GetPresetsBackoff groups workspace builds by preset ID.
54
+ -- Each preset is associated with exactly one template version ID.
54
55
-- For each group, the query checks up to N of the most recent jobs that occurred within the
55
56
-- lookback period, where N equals the number of desired instances for the corresponding preset.
56
- -- If at least one of the job within a group has failed, we should backoff on the corresponding template version ID.
57
- -- Query returns a list of template version IDs for which we should backoff.
57
+ -- If at least one of the job within a group has failed, we should backoff on the corresponding preset ID.
58
+ -- Query returns a list of preset IDs for which we should backoff.
58
59
-- Only active template versions with configured presets are considered.
59
60
-- We also return the number of failed workspace builds that occurred during the lookback period.
60
61
--
@@ -75,13 +76,13 @@ WITH filtered_builds AS (
75
76
AND wlb .transition = ' start' ::workspace_transition
76
77
),
77
78
time_sorted_builds AS (
78
- -- Group builds by template version , then sort each group by created_at.
79
+ -- Group builds by preset , then sort each group by created_at.
79
80
SELECT fb .template_version_id , fb .created_at , fb .preset_id , fb .job_status , fb .desired_instances ,
80
81
ROW_NUMBER() OVER (PARTITION BY fb .preset_id ORDER BY fb .created_at DESC ) as rn
81
82
FROM filtered_builds fb
82
83
),
83
84
failed_count AS (
84
- -- Count failed builds per template version/ preset in the given period
85
+ -- Count failed builds per preset in the given period
85
86
SELECT preset_id, COUNT (* ) AS num_failed
86
87
FROM filtered_builds
87
88
WHERE job_status = ' failed' ::provisioner_job_status
0 commit comments