worker: always send status "FINISHED"
The server hasn't used common.ImageBuildState to mark a job as successful or failed for a long time. Instead, it's using the job's return argument for that. (Jobs don't have a high-level concept of failing). Drop the check in the server, and always send "FINISHED" from the client for backwards compatibility.
This commit is contained in:
parent
b7cb2cff62
commit
d1f322ec6f
3 changed files with 4 additions and 15 deletions
|
|
@ -476,11 +476,9 @@ func main() {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
go WatchJob(ctx, job)
|
go WatchJob(ctx, job)
|
||||||
|
|
||||||
var status common.ImageBuildState
|
|
||||||
result, err := RunJob(job, store, kojiServers)
|
result, err := RunJob(job, store, kojiServers)
|
||||||
if err != nil || result.Success == false {
|
if err != nil || result.Success == false {
|
||||||
log.Printf(" Job failed: %v", err)
|
log.Printf(" Job failed: %v", err)
|
||||||
status = common.IBFailed
|
|
||||||
|
|
||||||
// Fail the jobs in any targets that expects it
|
// Fail the jobs in any targets that expects it
|
||||||
FailJob(job, kojiServers)
|
FailJob(job, kojiServers)
|
||||||
|
|
@ -502,13 +500,12 @@ func main() {
|
||||||
result.Success = false
|
result.Success = false
|
||||||
} else {
|
} else {
|
||||||
log.Printf(" 🎉 Job completed successfully: %v", job.Id())
|
log.Printf(" 🎉 Job completed successfully: %v", job.Id())
|
||||||
status = common.IBFinished
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// signal to WatchJob() that it can stop watching
|
// signal to WatchJob() that it can stop watching
|
||||||
cancel()
|
cancel()
|
||||||
|
|
||||||
err = job.Update(status, result)
|
err = job.Update(result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error reporting job result: %v", err)
|
log.Fatalf("Error reporting job result: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ type Client struct {
|
||||||
type Job interface {
|
type Job interface {
|
||||||
Id() uuid.UUID
|
Id() uuid.UUID
|
||||||
OSBuildArgs() (distro.Manifest, []*target.Target, error)
|
OSBuildArgs() (distro.Manifest, []*target.Target, error)
|
||||||
Update(status common.ImageBuildState, result *osbuild.Result) error
|
Update(result *osbuild.Result) error
|
||||||
Canceled() (bool, error)
|
Canceled() (bool, error)
|
||||||
UploadArtifact(name string, reader io.Reader) error
|
UploadArtifact(name string, reader io.Reader) error
|
||||||
}
|
}
|
||||||
|
|
@ -154,11 +154,11 @@ func (j *job) OSBuildArgs() (distro.Manifest, []*target.Target, error) {
|
||||||
return args.Manifest, args.Targets, nil
|
return args.Manifest, args.Targets, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *job) Update(status common.ImageBuildState, result *osbuild.Result) error {
|
func (j *job) Update(result *osbuild.Result) error {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
err := json.NewEncoder(&buf).Encode(api.UpdateJobJSONRequestBody{
|
err := json.NewEncoder(&buf).Encode(api.UpdateJobJSONRequestBody{
|
||||||
Result: result,
|
Result: result,
|
||||||
Status: status.ToString(),
|
Status: "FINISHED",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
|
||||||
"github.com/osbuild/osbuild-composer/internal/common"
|
|
||||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||||
"github.com/osbuild/osbuild-composer/internal/jobqueue"
|
"github.com/osbuild/osbuild-composer/internal/jobqueue"
|
||||||
"github.com/osbuild/osbuild-composer/internal/target"
|
"github.com/osbuild/osbuild-composer/internal/target"
|
||||||
|
|
@ -311,13 +310,6 @@ func (h *apiHandlers) UpdateJob(ctx echo.Context, idstr string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// The jobqueue doesn't support setting the status before a job is
|
|
||||||
// finished. This branch should never be hit, because the worker
|
|
||||||
// doesn't attempt this. Change the API to remove this awkwardness.
|
|
||||||
if body.Status != common.IBFinished && body.Status != common.IBFailed {
|
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "setting status of a job to waiting or running is not supported")
|
|
||||||
}
|
|
||||||
|
|
||||||
err = h.server.FinishJob(token, &OSBuildJobResult{OSBuildOutput: body.Result})
|
err = h.server.FinishJob(token, &OSBuildJobResult{OSBuildOutput: body.Result})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err {
|
switch err {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue