Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 23295f7

Browse files
authored
fix: Check for job status on another incoming (#1117)
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 23295f7

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
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"

site/src/api/typesGenerated.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ export interface CreateParameterRequest {
4646
readonly source_value: string
4747
}
4848

49-
// From codersdk/provisionerdaemons.go:37:6.
49+
// From codersdk/provisionerdaemons.go:46:6.
5050
export interface ProvisionerJob {
5151
readonly error: string
5252
readonly status: ProvisionerJobStatus
5353
}
5454

55-
// From codersdk/provisionerdaemons.go:47:6.
55+
// From codersdk/provisionerdaemons.go:56:6.
5656
export interface ProvisionerJobLog {
5757
readonly stage: string
5858
readonly output: string

0 commit comments

Comments
 (0)