diff --git a/internal/weldr/api.go b/internal/weldr/api.go index e1edcb606..61ad93834 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -169,6 +169,26 @@ type composeStatus struct { Result *osbuild.Result } +func composeStateFromJobStatus(js *worker.JobStatus) common.ComposeState { + if js.Canceled { + return common.CFailed + } + + if js.Started.IsZero() { + return common.CWaiting + } + + if js.Finished.IsZero() { + return common.CRunning + } + + if js.Result.OSBuildOutput != nil && js.Result.OSBuildOutput.Success { + return common.CFinished + } + + return common.CFailed +} + // Returns the state of the image in `compose` and the times the job was // queued, started, and finished. Assumes that there's only one image in the // compose. @@ -202,7 +222,7 @@ func (api *API) getComposeStatus(compose store.Compose) *composeStatus { // is it ok to ignore this error? jobStatus, _ := api.workers.JobStatus(jobId) return &composeStatus{ - State: jobStatus.State, + State: composeStateFromJobStatus(jobStatus), Queued: jobStatus.Queued, Started: jobStatus.Started, Finished: jobStatus.Finished, diff --git a/internal/worker/server.go b/internal/worker/server.go index ec81739a2..26a23e47e 100644 --- a/internal/worker/server.go +++ b/internal/worker/server.go @@ -44,7 +44,6 @@ type Server struct { } type JobStatus struct { - State common.ComposeState Queued time.Time Started time.Time Finished time.Time @@ -105,21 +104,8 @@ func (s *Server) JobStatus(id uuid.UUID) (*JobStatus, error) { if err != nil { return nil, err } - state := common.CWaiting - if canceled { - state = common.CFailed - } else if !finished.IsZero() { - if result.OSBuildOutput != nil && result.OSBuildOutput.Success { - state = common.CFinished - } else { - state = common.CFailed - } - } else if !started.IsZero() { - state = common.CRunning - } return &JobStatus{ - State: state, Queued: queued, Started: started, Finished: finished,