worker: make worker.Client job-agnostic

Move the fact that the worker is requesting jobs of type "osbuild" out
of the client library.

For one, require consumers to pass accepted job types to RequestJobs()
and allow querying for the job type with the new Type() function.

Also, make OSBuildArgs() and Update() generic, requiring to pass an
argument that matches the job type.
This commit is contained in:
Lars Karlitski 2020-11-01 17:57:54 +01:00
parent 07f21d089e
commit c15c17960b
2 changed files with 20 additions and 21 deletions

View file

@ -105,7 +105,8 @@ func RunJob(job worker.Job, store string, kojiServers map[string]koji.GSSAPICred
}
}()
args, err := job.OSBuildArgs()
var args worker.OSBuildJob
err = job.Args(&args)
if err != nil {
return err
}
@ -444,12 +445,12 @@ func main() {
for {
fmt.Println("Waiting for a new job...")
job, err := client.RequestJob()
job, err := client.RequestJob([]string{"osbuild"})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Running job %v\n", job.Id())
fmt.Printf("Running '%s' job %v\n", job.Type(), job.Id())
ctx, cancelWatcher := context.WithCancel(context.Background())
go WatchJob(ctx, job)