osbuild-worker: refactor reporting the job status to deref
The previous implementation exited before reporting back to the worker API in few branches. This left the compose status in RUNNING state even though the worker did not work of the job any more. Refactoring the API call into the `deref` part makes sure it gets called every time. This commit only moves bits of the code around so that the status gets back to osbuild-composer, but it still doesn't contain any useful information in case osbuild fails etc. This will be introduced in subsequent commits.
This commit is contained in:
parent
aa21b57daf
commit
87942865ba
1 changed files with 38 additions and 31 deletions
|
|
@ -70,17 +70,50 @@ func osbuildStagesToRPMs(stages []osbuild.StageResult) []koji.RPM {
|
|||
}
|
||||
|
||||
func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
||||
outputDirectory, err := ioutil.TempDir(impl.Output, job.Id().String()+"-*")
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating temporary output directory: %v", err)
|
||||
// Initialize variables needed for reporting back to osbuild-composer
|
||||
var outputDirectory string
|
||||
var r []error
|
||||
var targetResults []*target.TargetResult
|
||||
var osbuildOutput *osbuild.Result = &osbuild.Result{
|
||||
Success: false,
|
||||
}
|
||||
|
||||
defer func() {
|
||||
err := os.RemoveAll(outputDirectory)
|
||||
var targetErrors []string
|
||||
for _, err := range r {
|
||||
errStr := err.Error()
|
||||
fmt.Printf("target errored: %s", errStr)
|
||||
targetErrors = append(targetErrors, errStr)
|
||||
}
|
||||
|
||||
var uploadstatus string = "failure"
|
||||
if len(targetErrors) == 0 {
|
||||
uploadstatus = "success"
|
||||
}
|
||||
|
||||
// In all cases it is necessary to report result back to osbuild-composer worker API
|
||||
err := job.Update(&worker.OSBuildJobResult{
|
||||
Success: osbuildOutput.Success && len(targetErrors) == 0,
|
||||
OSBuildOutput: osbuildOutput,
|
||||
TargetErrors: targetErrors,
|
||||
TargetResults: targetResults,
|
||||
UploadStatus: uploadstatus,
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("Error reporting job result: %v", err)
|
||||
}
|
||||
|
||||
err = os.RemoveAll(outputDirectory)
|
||||
if err != nil {
|
||||
log.Printf("Error removing temporary output directory (%s): %v", outputDirectory, err)
|
||||
}
|
||||
}()
|
||||
|
||||
outputDirectory, err := ioutil.TempDir(impl.Output, job.Id().String()+"-*")
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating temporary output directory: %v", err)
|
||||
}
|
||||
|
||||
var args worker.OSBuildJob
|
||||
err = job.Args(&args)
|
||||
if err != nil {
|
||||
|
|
@ -99,7 +132,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
|
||||
start_time := time.Now()
|
||||
|
||||
osbuildOutput, err := RunOSBuild(args.Manifest, impl.Store, outputDirectory, exports, os.Stderr)
|
||||
osbuildOutput, err = RunOSBuild(args.Manifest, impl.Store, outputDirectory, exports, os.Stderr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -133,9 +166,6 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
}
|
||||
}
|
||||
|
||||
var r []error
|
||||
var targetResults []*target.TargetResult
|
||||
|
||||
for _, t := range args.Targets {
|
||||
switch options := t.Options.(type) {
|
||||
case *target.LocalTargetOptions:
|
||||
|
|
@ -560,28 +590,5 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
}
|
||||
}
|
||||
|
||||
var targetErrors []string
|
||||
for _, err := range r {
|
||||
errStr := err.Error()
|
||||
fmt.Printf("target errored: %s", errStr)
|
||||
targetErrors = append(targetErrors, errStr)
|
||||
}
|
||||
|
||||
var uploadstatus string = "failure"
|
||||
if len(targetErrors) == 0 {
|
||||
uploadstatus = "success"
|
||||
}
|
||||
|
||||
err = job.Update(&worker.OSBuildJobResult{
|
||||
Success: osbuildOutput.Success && len(targetErrors) == 0,
|
||||
OSBuildOutput: osbuildOutput,
|
||||
TargetErrors: targetErrors,
|
||||
TargetResults: targetResults,
|
||||
UploadStatus: uploadstatus,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error reporting job result: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue