worker: allow passing different jobs to workers

Until now, all jobs were put as "osbuild" jobs into the job queue and
the worker API hard-coded sending an osbuild manifest and upload
targets.

Change the API to take a "type" and "args" keys, which are equivalent to
the job-queue's type and args. Workers continue to support only osbuild
jobs, but this makes other jobs possible in the future.
This commit is contained in:
Lars Karlitski 2020-09-20 17:22:31 +02:00 committed by Tom Gundersen
parent 5b57814664
commit d3c99b8e93
5 changed files with 39 additions and 20 deletions

View file

@ -5,6 +5,7 @@ import (
"context"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io"
"net"
@ -35,10 +36,10 @@ type Job interface {
type job struct {
requester *http.Client
id uuid.UUID
manifest distro.Manifest
targets []*target.Target
location string
artifactLocation string
jobType string
args json.RawMessage
}
func NewClient(baseURL string, conf *tls.Config) (*Client, error) {
@ -115,8 +116,8 @@ func (c *Client) RequestJob() (Job, error) {
return &job{
requester: c.requester,
id: jr.Id,
manifest: jr.Manifest,
targets: jr.Targets,
jobType: jr.Type,
args: jr.Args,
location: location.String(),
artifactLocation: artifactLocation.String(),
}, nil
@ -127,7 +128,17 @@ func (j *job) Id() uuid.UUID {
}
func (j *job) OSBuildArgs() (distro.Manifest, []*target.Target, error) {
return j.manifest, j.targets, nil
if j.jobType != "osbuild" {
return nil, nil, errors.New("not an osbuild job")
}
var args OSBuildJob
err := json.Unmarshal(j.args, &args)
if err != nil {
return nil, nil, fmt.Errorf("error parsing osbuild job arguments: %v", err)
}
return args.Manifest, args.Targets, nil
}
func (j *job) Update(status common.ImageBuildState, result *osbuild.Result) error {