worker: use OSBuildJobResult consistently
Workers reported status via an `osbuild.Result`, which only includes osbuild output. Make it report OSBuildJobResult instead, which was meant to be used for this purpose and is already used as the result type in the jobqueue. While at it, add any errors produced by targets into this struct, as well as an overall success flag. Note that this breaks older workers returning the result of an osbuild job to a new composer. I think this is fine in this case, for two reasons: 1. We don't support running different versions of the worker and composer in the weldr API, and remote workers aren't widely used yet. 2. Both osbuild.Result and worker.OSBuildJobResult have a top-level `Success` boolean. Thus, logs are lost in such cases, but the overall status of the compose is not.
This commit is contained in:
parent
a0f080c497
commit
299a5e52ab
7 changed files with 41 additions and 63 deletions
|
|
@ -249,7 +249,7 @@ func composeStatusFromJobStatus(js *worker.JobStatus) string {
|
|||
return StatusRunning
|
||||
}
|
||||
|
||||
if js.Result.OSBuildOutput != nil && js.Result.OSBuildOutput.Success {
|
||||
if js.Result.Success {
|
||||
return StatusSuccess
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ func composeStatusFromJobStatus(js *worker.JobStatus) string {
|
|||
return "pending"
|
||||
}
|
||||
|
||||
if js.Result.OSBuildOutput != nil && js.Result.OSBuildOutput.Success {
|
||||
if js.Result.Success {
|
||||
return "success"
|
||||
}
|
||||
|
||||
|
|
@ -260,7 +260,7 @@ func imageStatusFromJobStatus(js *worker.JobStatus) string {
|
|||
return "building"
|
||||
}
|
||||
|
||||
if js.Result.OSBuildOutput != nil && js.Result.OSBuildOutput.Success {
|
||||
if js.Result.Success {
|
||||
return "success"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ func composeStateFromJobStatus(js *worker.JobStatus) ComposeState {
|
|||
return ComposeRunning
|
||||
}
|
||||
|
||||
if js.Result.OSBuildOutput != nil && js.Result.OSBuildOutput.Success {
|
||||
if js.Result.Success {
|
||||
return ComposeFinished
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import (
|
|||
|
||||
"github.com/google/uuid"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||
"github.com/osbuild/osbuild-composer/internal/worker/api"
|
||||
)
|
||||
|
||||
|
|
@ -26,7 +25,7 @@ type Client struct {
|
|||
type Job interface {
|
||||
Id() uuid.UUID
|
||||
OSBuildArgs() (*OSBuildJob, error)
|
||||
Update(result *osbuild.Result) error
|
||||
Update(result *OSBuildJobResult) error
|
||||
Canceled() (bool, error)
|
||||
UploadArtifact(name string, reader io.Reader) error
|
||||
}
|
||||
|
|
@ -152,11 +151,10 @@ func (j *job) OSBuildArgs() (*OSBuildJob, error) {
|
|||
return &args, nil
|
||||
}
|
||||
|
||||
func (j *job) Update(result *osbuild.Result) error {
|
||||
func (j *job) Update(result *OSBuildJobResult) error {
|
||||
var buf bytes.Buffer
|
||||
err := json.NewEncoder(&buf).Encode(api.UpdateJobJSONRequestBody{
|
||||
Result: result,
|
||||
Status: "FINISHED",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/osbuild"
|
||||
"github.com/osbuild/osbuild-composer/internal/target"
|
||||
|
|
@ -22,7 +21,9 @@ type OSBuildJob struct {
|
|||
}
|
||||
|
||||
type OSBuildJobResult struct {
|
||||
Success bool `json:"success"`
|
||||
OSBuildOutput *osbuild.Result `json:"osbuild_output,omitempty"`
|
||||
TargetErrors []string `json:"target_errors,omitempty"`
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -46,8 +47,7 @@ type getJobResponse struct {
|
|||
}
|
||||
|
||||
type updateJobRequest struct {
|
||||
Status common.ImageBuildState `json:"status"`
|
||||
Result *osbuild.Result `json:"result"`
|
||||
Result json.RawMessage `json:"result"`
|
||||
}
|
||||
|
||||
type updateJobResponse struct {
|
||||
|
|
|
|||
|
|
@ -96,6 +96,12 @@ func (s *Server) JobStatus(id uuid.UUID) (*JobStatus, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// For backwards compatibility: OSBuildJobResult didn't use to have a
|
||||
// top-level `Success` flag. Override it here by looking into the job.
|
||||
if result.Success == false && result.OSBuildOutput != nil {
|
||||
result.Success = result.OSBuildOutput.Success && len(result.TargetErrors) == 0
|
||||
}
|
||||
|
||||
return &JobStatus{
|
||||
Queued: queued,
|
||||
Started: started,
|
||||
|
|
@ -187,7 +193,7 @@ func (s *Server) RunningJob(token uuid.UUID) (uuid.UUID, error) {
|
|||
return jobId, nil
|
||||
}
|
||||
|
||||
func (s *Server) FinishJob(token uuid.UUID, result *OSBuildJobResult) error {
|
||||
func (s *Server) FinishJob(token uuid.UUID, result json.RawMessage) error {
|
||||
s.runningMutex.Lock()
|
||||
defer s.runningMutex.Unlock()
|
||||
|
||||
|
|
@ -303,7 +309,7 @@ func (h *apiHandlers) UpdateJob(ctx echo.Context, idstr string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = h.server.FinishJob(token, &OSBuildJobResult{OSBuildOutput: body.Result})
|
||||
err = h.server.FinishJob(token, body.Result)
|
||||
if err != nil {
|
||||
switch err {
|
||||
case ErrTokenNotExist:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue