osbuild-{composer/worker}: exit cleanly
Only panic on compile-time errors (e.g., built for unsupported architecture). Otherwise, use log.Fatalf(), which is equivalent to printing and exiting with return code 1. Only ever do this from main(), in all other cases pass on the error object. This is mostly relevant when the server disconects, in which case we'll get EOF, and will now restart cleanly instead of panicing. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
42dfbf7da6
commit
118b185fdd
2 changed files with 16 additions and 13 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
|
|
@ -76,40 +77,42 @@ func (c *ComposerClient) UpdateJob(job *jobqueue.Job, status string, image *stor
|
|||
return nil
|
||||
}
|
||||
|
||||
func handleJob(client *ComposerClient, distro distro.Distro) {
|
||||
func handleJob(client *ComposerClient, distro distro.Distro) error {
|
||||
fmt.Println("Waiting for a new job...")
|
||||
job, err := client.AddJob()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
|
||||
client.UpdateJob(job, "RUNNING", nil)
|
||||
err = client.UpdateJob(job, "RUNNING", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Running job %s\n", job.ID.String())
|
||||
image, err, errs := job.Run(distro)
|
||||
if err != nil {
|
||||
client.UpdateJob(job, "FAILED", nil)
|
||||
return
|
||||
return client.UpdateJob(job, "FAILED", nil)
|
||||
}
|
||||
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
client.UpdateJob(job, "FAILED", nil)
|
||||
return
|
||||
return client.UpdateJob(job, "FAILED", nil)
|
||||
}
|
||||
}
|
||||
|
||||
client.UpdateJob(job, "FINISHED", image)
|
||||
return client.UpdateJob(job, "FINISHED", image)
|
||||
}
|
||||
|
||||
func main() {
|
||||
distro, err := distro.FromHost()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatalf("Could not determine distro from host: " + err.Error())
|
||||
}
|
||||
|
||||
client := NewClient()
|
||||
for {
|
||||
handleJob(client, distro)
|
||||
err = handleJob(client, distro)
|
||||
log.Fatalf("Failed to handle job: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue