From 3d8878c55a6c28572a0c474de47a72488b46c56e Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Mon, 25 Apr 2022 01:57:44 +0000 Subject: [PATCH] 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. --- coderd/workspaces.go | 2 +- codersdk/provisionerdaemons.go | 9 +++++++++ site/src/api/typesGenerated.ts | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/coderd/workspaces.go b/coderd/workspaces.go index 0ae2e0524772b..67402cc925642 100644 --- a/coderd/workspaces.go +++ b/coderd/workspaces.go @@ -166,7 +166,7 @@ func (api *api) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) { priorHistory, err := api.Database.GetWorkspaceBuildByWorkspaceIDWithoutAfter(r.Context(), workspace.ID) if err == nil { priorJob, err := api.Database.GetProvisionerJobByID(r.Context(), priorHistory.JobID) - if err == nil && !priorJob.CompletedAt.Valid { + if err == nil && convertProvisionerJob(priorJob).Status.Active() { httpapi.Write(rw, http.StatusConflict, httpapi.Response{ Message: "a workspace build is already active", }) diff --git a/codersdk/provisionerdaemons.go b/codersdk/provisionerdaemons.go index fba4a97cf0353..c726f8f255eef 100644 --- a/codersdk/provisionerdaemons.go +++ b/codersdk/provisionerdaemons.go @@ -25,6 +25,15 @@ type ProvisionerDaemon database.ProvisionerDaemon // ProvisionerJobStaus represents the at-time state of a job. type ProvisionerJobStatus string +// Active returns whether the job is still active or not. +// It returns true if canceling as well, since the job isn't +// in an entirely inactive state yet. +func (p ProvisionerJobStatus) Active() bool { + return p == ProvisionerJobPending || + p == ProvisionerJobRunning || + p == ProvisionerJobCanceling +} + const ( ProvisionerJobPending ProvisionerJobStatus = "pending" ProvisionerJobRunning ProvisionerJobStatus = "running" diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index 1aaa22b3ddb8a..9c2815b6efa79 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -46,13 +46,13 @@ export interface CreateParameterRequest { readonly source_value: string } -// From codersdk/provisionerdaemons.go:37:6. +// From codersdk/provisionerdaemons.go:46:6. export interface ProvisionerJob { readonly error: string readonly status: ProvisionerJobStatus } -// From codersdk/provisionerdaemons.go:47:6. +// From codersdk/provisionerdaemons.go:56:6. export interface ProvisionerJobLog { readonly stage: string readonly output: string