worker: generalize job types in the server

The worker server was heavily tied to OSBuildJob(Result). Untie it so
that it can deal with different job types in the future.

This necessitates a change in the jobqueue: Dequeue() now returns the
job type, as well as job arguments as json.RawMessage. This is so that
the server can wait on multiple job types with different argument
types.

The weldr, composer, and koji APIs continue to use only "osbuild" jobs.
This commit is contained in:
Lars Karlitski 2020-11-02 21:49:18 +01:00
parent 6b6cd7ca9f
commit 59e73a686a
9 changed files with 108 additions and 85 deletions

View file

@ -215,17 +215,18 @@ func (server *Server) ComposeStatus(w http.ResponseWriter, r *http.Request, id s
return
}
status, err := server.workers.JobStatus(jobId)
var result worker.OSBuildJobResult
status, err := server.workers.JobStatus(jobId, &result)
if err != nil {
http.Error(w, fmt.Sprintf("Job %s not found: %s", id, err), http.StatusNotFound)
return
}
response := ComposeStatus{
Status: composeStatusFromJobStatus(status),
Status: composeStatusFromJobStatus(status, &result),
ImageStatuses: &[]ImageStatus{
{
Status: composeStatusFromJobStatus(status),
Status: composeStatusFromJobStatus(status, &result),
},
},
}
@ -236,7 +237,7 @@ func (server *Server) ComposeStatus(w http.ResponseWriter, r *http.Request, id s
}
}
func composeStatusFromJobStatus(js *worker.JobStatus) string {
func composeStatusFromJobStatus(js *worker.JobStatus, result *worker.OSBuildJobResult) string {
if js.Canceled {
return StatusFailure
}
@ -249,7 +250,7 @@ func composeStatusFromJobStatus(js *worker.JobStatus) string {
return StatusRunning
}
if js.Result.Success {
if result.Success {
return StatusSuccess
}