worker/server: make JobStatus() return JobStatus struct
Personally, I don't like methods returning too much values. I think it's easy to assign the values in an incorrect order and thus interpreting them in a wrong way. Also, the following commits will make JobStatus() return also the JobResult, which would make the number of returned values even higher. Not a functional change.
This commit is contained in:
parent
8b58d2c91a
commit
fa5b775718
2 changed files with 20 additions and 9 deletions
|
|
@ -168,8 +168,9 @@ func (api *API) getComposeState(compose store.Compose) (state common.ComposeStat
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
state, queued, started, finished, _ = api.workers.JobStatus(jobId)
|
// is it ok to ignore this error?
|
||||||
return
|
jobStatus, _ := api.workers.JobStatus(jobId)
|
||||||
|
return jobStatus.State, jobStatus.Queued, jobStatus.Started, jobStatus.Finished
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyRequestVersion(writer http.ResponseWriter, params httprouter.Params, minVersion uint) bool {
|
func verifyRequestVersion(writer http.ResponseWriter, params httprouter.Params, minVersion uint) bool {
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,13 @@ type Server struct {
|
||||||
imageWriter WriteImageFunc
|
imageWriter WriteImageFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type JobStatus struct {
|
||||||
|
State common.ComposeState
|
||||||
|
Queued time.Time
|
||||||
|
Started time.Time
|
||||||
|
Finished time.Time
|
||||||
|
}
|
||||||
|
|
||||||
type WriteImageFunc func(composeID uuid.UUID, imageBuildID int, reader io.Reader) error
|
type WriteImageFunc func(composeID uuid.UUID, imageBuildID int, reader io.Reader) error
|
||||||
|
|
||||||
func NewServer(logger *log.Logger, jobs jobqueue.JobQueue, imageWriter WriteImageFunc) *Server {
|
func NewServer(logger *log.Logger, jobs jobqueue.JobQueue, imageWriter WriteImageFunc) *Server {
|
||||||
|
|
@ -78,15 +85,15 @@ func (s *Server) Enqueue(manifest *osbuild.Manifest, targets []*target.Target) (
|
||||||
return s.jobs.Enqueue("osbuild", job, nil)
|
return s.jobs.Enqueue("osbuild", job, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) JobStatus(id uuid.UUID) (state common.ComposeState, queued, started, finished time.Time, err error) {
|
func (s *Server) JobStatus(id uuid.UUID) (*JobStatus, error) {
|
||||||
var canceled bool
|
var canceled bool
|
||||||
var result OSBuildJobResult
|
var result OSBuildJobResult
|
||||||
|
|
||||||
queued, started, finished, canceled, err = s.jobs.JobStatus(id, &result)
|
queued, started, finished, canceled, err := s.jobs.JobStatus(id, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
|
state := common.CWaiting
|
||||||
if canceled {
|
if canceled {
|
||||||
state = common.CFailed
|
state = common.CFailed
|
||||||
} else if !finished.IsZero() {
|
} else if !finished.IsZero() {
|
||||||
|
|
@ -97,11 +104,14 @@ func (s *Server) JobStatus(id uuid.UUID) (state common.ComposeState, queued, sta
|
||||||
}
|
}
|
||||||
} else if !started.IsZero() {
|
} else if !started.IsZero() {
|
||||||
state = common.CRunning
|
state = common.CRunning
|
||||||
} else {
|
|
||||||
state = common.CWaiting
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return &JobStatus{
|
||||||
|
State: state,
|
||||||
|
Queued: queued,
|
||||||
|
Started: started,
|
||||||
|
Finished: finished,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) JobResult(id uuid.UUID) (common.ComposeState, *common.ComposeResult, error) {
|
func (s *Server) JobResult(id uuid.UUID) (common.ComposeState, *common.ComposeResult, error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue