@@ -96,7 +96,8 @@ LEFT JOIN LATERAL (
96
96
provisioner_jobs .updated_at ,
97
97
provisioner_jobs .canceled_at ,
98
98
provisioner_jobs .completed_at ,
99
- provisioner_jobs .error
99
+ provisioner_jobs .error ,
100
+ provisioner_jobs .job_status
100
101
FROM
101
102
workspace_builds
102
103
LEFT JOIN
@@ -128,63 +129,43 @@ WHERE
128
129
AND CASE
129
130
WHEN @status :: text != ' ' THEN
130
131
CASE
131
- WHEN @status = ' pending' THEN
132
- latest_build .started_at IS NULL
132
+ -- Some workspace specific status refer to the transition
133
+ -- type. By default, the standard provisioner job status
134
+ -- search strings are supported.
135
+ -- 'running' states
133
136
WHEN @status = ' starting' THEN
134
- latest_build .started_at IS NOT NULL AND
135
- latest_build . canceled_at IS NULL AND
136
- latest_build . completed_at IS NULL AND
137
+ latest_build .job_status = ' running ' AND
138
+ -- TODO: Should we drop the interval? Hung workspaces
139
+ -- should still be their last state?
137
140
latest_build .updated_at - INTERVAL ' 30 seconds' < NOW() AND
138
141
latest_build .transition = ' start' ::workspace_transition
139
-
140
- WHEN @status = ' running' THEN
141
- latest_build .completed_at IS NOT NULL AND
142
- latest_build .canceled_at IS NULL AND
143
- latest_build .error IS NULL AND
144
- latest_build .transition = ' start' ::workspace_transition
145
-
146
142
WHEN @status = ' stopping' THEN
147
- latest_build .started_at IS NOT NULL AND
148
- latest_build . canceled_at IS NULL AND
149
- latest_build . completed_at IS NULL AND
143
+ latest_build .job_status = ' running ' AND
144
+ -- TODO: Should we drop the interval? Hung workspaces
145
+ -- should still be their last state?
150
146
latest_build .updated_at - INTERVAL ' 30 seconds' < NOW() AND
151
147
latest_build .transition = ' stop' ::workspace_transition
148
+ WHEN @status = ' deleting' THEN
149
+ latest_build .job_status = ' running' AND
150
+ -- TODO: Should we drop the interval? Hung workspaces
151
+ -- should still be their last state?
152
+ latest_build .updated_at - INTERVAL ' 30 seconds' < NOW() AND
153
+ latest_build .transition = ' delete' ::workspace_transition
152
154
155
+ -- 'succeeded' states
156
+ WHEN @status = ' deleted' THEN
157
+ latest_build .job_status = ' succeeded' AND
158
+ latest_build .transition = ' delete' ::workspace_transition
153
159
WHEN @status = ' stopped' THEN
154
- latest_build .completed_at IS NOT NULL AND
155
- latest_build .canceled_at IS NULL AND
156
- latest_build .error IS NULL AND
160
+ latest_build .job_status = ' succeeded' AND
157
161
latest_build .transition = ' stop' ::workspace_transition
162
+ WHEN @status = ' started' THEN
163
+ latest_build .job_status = ' succeeded' AND
164
+ latest_build .transition = ' start' ::workspace_transition
158
165
159
- WHEN @status = ' failed' THEN
160
- (latest_build .canceled_at IS NOT NULL AND
161
- latest_build .error IS NOT NULL ) OR
162
- (latest_build .completed_at IS NOT NULL AND
163
- latest_build .error IS NOT NULL )
164
-
165
- WHEN @status = ' canceling' THEN
166
- latest_build .canceled_at IS NOT NULL AND
167
- latest_build .completed_at IS NULL
168
-
169
- WHEN @status = ' canceled' THEN
170
- latest_build .canceled_at IS NOT NULL AND
171
- latest_build .completed_at IS NOT NULL
172
-
173
- WHEN @status = ' deleted' THEN
174
- latest_build .started_at IS NOT NULL AND
175
- latest_build .canceled_at IS NULL AND
176
- latest_build .completed_at IS NOT NULL AND
177
- latest_build .updated_at - INTERVAL ' 30 seconds' < NOW() AND
178
- latest_build .transition = ' delete' ::workspace_transition AND
179
- -- If the error field is not null, the status is 'failed'
180
- latest_build .error IS NULL
181
-
182
- WHEN @status = ' deleting' THEN
183
- latest_build .completed_at IS NULL AND
184
- latest_build .canceled_at IS NULL AND
185
- latest_build .error IS NULL AND
186
- latest_build .transition = ' delete' ::workspace_transition
187
-
166
+ WHEN @status != ' ' THEN
167
+ -- By default just match the job status exactly
168
+ latest_build .job_status = @status
188
169
ELSE
189
170
true
190
171
END
0 commit comments