From 240972896055fd4c3d1983cbfd0d0cb304fbab67 Mon Sep 17 00:00:00 2001 From: Michael Hohn Date: Fri, 14 Mar 2025 12:45:36 -0700 Subject: [PATCH] fix: reconciled status names between server/agent/vscode-codeql --- pkg/agent/agent.go | 15 ++++++++------- pkg/common/types.go | 23 +++++++++++++---------- pkg/server/server.go | 8 ++++---- pkg/state/state_local.go | 5 +++-- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/pkg/agent/agent.go b/pkg/agent/agent.go index 9b31c22..f579534 100644 --- a/pkg/agent/agent.go +++ b/pkg/agent/agent.go @@ -4,17 +4,18 @@ import ( "context" "fmt" "log/slog" + "os" + "path/filepath" + "runtime" + "sync" + "time" + "github.com/hohn/mrvacommander/pkg/artifactstore" "github.com/hohn/mrvacommander/pkg/codeql" "github.com/hohn/mrvacommander/pkg/common" "github.com/hohn/mrvacommander/pkg/qldbstore" "github.com/hohn/mrvacommander/pkg/queue" "github.com/hohn/mrvacommander/utils" - "os" - "path/filepath" - "runtime" - "sync" - "time" "github.com/elastic/go-sysinfo" "github.com/google/uuid" @@ -153,7 +154,7 @@ func RunAnalysisJob( Spec: job.Spec, ResultCount: 0, ResultLocation: artifactstore.ArtifactLocation{}, - Status: common.StatusError, + Status: common.StatusFailed, } // Create a temporary directory @@ -218,7 +219,7 @@ func RunAnalysisJob( Spec: job.Spec, ResultCount: runResult.ResultCount, ResultLocation: resultsLocation, - Status: common.StatusSuccess, + Status: common.StatusSucceeded, SourceLocationPrefix: runResult.SourceLocationPrefix, DatabaseSHA: runResult.DatabaseSHA, } diff --git a/pkg/common/types.go b/pkg/common/types.go index 104afe4..7e7b05b 100644 --- a/pkg/common/types.go +++ b/pkg/common/types.go @@ -10,25 +10,28 @@ type NameWithOwner struct { type Status int const ( - StatusInProgress = iota - StatusQueued - StatusError - StatusSuccess + StatusPending Status = iota + StatusInProgress + StatusSucceeded StatusFailed + StatusCanceled + StatusTimedOut ) func (s Status) ToExternalString() string { switch s { + case StatusPending: + return "pending" case StatusInProgress: - return "in_progress" - case StatusQueued: - return "queued" - case StatusError: - return "error" - case StatusSuccess: + return "inProgress" + case StatusSucceeded: return "succeeded" case StatusFailed: return "failed" + case StatusCanceled: + return "canceled" + case StatusTimedOut: + return "timedOut" default: return "unknown" } diff --git a/pkg/server/server.go b/pkg/server/server.go index c201ec5..f4658a7 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -41,7 +41,7 @@ func (c *CommanderSingle) startAnalyses( QueryLanguage: queryLanguage, } c.v.Queue.Jobs() <- info - c.v.State.SetStatus(jobSpec, common.StatusQueued) + c.v.State.SetStatus(jobSpec, common.StatusPending) c.v.State.AddJob(info) } } @@ -132,7 +132,7 @@ func (c *CommanderSingle) submitEmptyStatusResponse(w http.ResponseWriter, scannedRepos := []common.ScannedRepo{} var jobStatus common.Status - jobStatus = common.StatusSuccess + jobStatus = common.StatusSucceeded status := common.StatusResponse{ SessionId: jsSessionID, @@ -191,7 +191,7 @@ func (c *CommanderSingle) submitStatusResponse(w http.ResponseWriter, js common. var artifactSize int var resultCount int - if status != common.StatusSuccess { + if status != common.StatusSucceeded { // If the job is not successful, we don't need to get the result artifactSize = 0 resultCount = 0 @@ -436,7 +436,7 @@ func (c *CommanderSingle) sendArtifactDownloadResponse(w http.ResponseWriter, jo return } - if jobStatus == common.StatusSuccess { + if jobStatus == common.StatusSucceeded { jobResult, err := c.v.State.GetResult(jobSpec) if err != nil { slog.Error(err.Error()) diff --git a/pkg/state/state_local.go b/pkg/state/state_local.go index 7bbade2..7817f5d 100644 --- a/pkg/state/state_local.go +++ b/pkg/state/state_local.go @@ -3,9 +3,10 @@ package state import ( "fmt" "log/slog" + "sync" + "github.com/hohn/mrvacommander/pkg/common" "github.com/hohn/mrvacommander/pkg/queue" - "sync" ) type LocalState struct { @@ -97,7 +98,7 @@ func (s *LocalState) GetStatus(js common.JobSpec) (common.Status, error) { s.mutex.Lock() defer s.mutex.Unlock() if _, ok := s.status[js]; !ok { - return common.StatusError, fmt.Errorf("status not found for job spec %v", js) + return common.StatusFailed, fmt.Errorf("status not found for job spec %v", js) } return s.status[js], nil }