worker: remove State from JobStatus

This state is specific to weldr. Previous commits removed it from the
other APIs, because they use different values.

Move the conversion into the weldr API.
This commit is contained in:
Lars Karlitski 2020-10-24 11:57:02 +02:00
parent 7441012e62
commit 669b612d96
2 changed files with 21 additions and 15 deletions

View file

@ -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,

View file

@ -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,