Skip to content

Commit 373c39e

Browse files
committed
fix: Check for job status on another incoming
If a job silently failed, it wasn't possible for another one to execute. This fixes it by using the API status to return active state.
1 parent db7ed4d commit 373c39e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

coderd/workspaces.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (api *api) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) {
166166
priorHistory, err := api.Database.GetWorkspaceBuildByWorkspaceIDWithoutAfter(r.Context(), workspace.ID)
167167
if err == nil {
168168
priorJob, err := api.Database.GetProvisionerJobByID(r.Context(), priorHistory.JobID)
169-
if err == nil && !priorJob.CompletedAt.Valid {
169+
if err == nil && convertProvisionerJob(priorJob).Status.Active() {
170170
httpapi.Write(rw, http.StatusConflict, httpapi.Response{
171171
Message: "a workspace build is already active",
172172
})

codersdk/provisionerdaemons.go

+9
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ type ProvisionerDaemon database.ProvisionerDaemon
2525
// ProvisionerJobStaus represents the at-time state of a job.
2626
type ProvisionerJobStatus string
2727

28+
// Active returns whether the job is still active or not.
29+
// It returns true if canceling as well, since the job isn't
30+
// in an entirely inactive state yet.
31+
func (p ProvisionerJobStatus) Active() bool {
32+
return p == ProvisionerJobPending ||
33+
p == ProvisionerJobRunning ||
34+
p == ProvisionerJobCanceling
35+
}
36+
2837
const (
2938
ProvisionerJobPending ProvisionerJobStatus = "pending"
3039
ProvisionerJobRunning ProvisionerJobStatus = "running"

0 commit comments

Comments
 (0)