jobqueue: cleanup API a bit and unify the two job stores

Let the store in weldr be the only one that keeps state, and push
updates directly there. This fixes a bug where there was an ID mismatch.

Change the API to not let the caller pick the UUID, but provide it
in the response. Use the same UUID as is used to identify composes,
this makes it simpler to trace what is going on.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2019-10-01 17:06:37 +02:00 committed by Lars Karlitski
parent 7f82ef4043
commit 0880014edf
5 changed files with 17 additions and 100 deletions

View file

@ -12,9 +12,9 @@ import (
)
type Job struct {
ID uuid.UUID
Pipeline pipeline.Pipeline
Targets []target.Target
ID uuid.UUID `json:"id"`
Pipeline pipeline.Pipeline `json:"pipeline"`
Targets []target.Target `json:"targets"`
}
func (job *Job) Run() error {

View file

@ -8,11 +8,6 @@ import (
"fmt"
"net"
"net/http"
"github.com/google/uuid"
"osbuild-composer/internal/pipeline"
"osbuild-composer/internal/target"
)
type ComposerClient struct {
@ -32,19 +27,10 @@ func NewClient() *ComposerClient {
func (c *ComposerClient) AddJob() (*Job, error) {
type request struct {
ID string `json:"id"`
}
type reply struct {
Pipeline *pipeline.Pipeline `json:"pipeline"`
Targets *[]target.Target `json:"targets"`
}
job := &Job{
ID: uuid.New(),
}
var b bytes.Buffer
json.NewEncoder(&b).Encode(request{job.ID.String()})
json.NewEncoder(&b).Encode(request{})
response, err := c.client.Post("http://localhost/job-queue/v1/jobs", "application/json", &b)
if err != nil {
return nil, err
@ -55,10 +41,8 @@ func (c *ComposerClient) AddJob() (*Job, error) {
return nil, errors.New("couldn't create job")
}
err = json.NewDecoder(response.Body).Decode(&reply{
Pipeline: &job.Pipeline,
Targets: &job.Targets,
})
job := &Job{}
err = json.NewDecoder(response.Body).Decode(job)
if err != nil {
return nil, err
}
@ -102,6 +86,8 @@ func main() {
panic(err)
}
client.UpdateJob(job, "RUNNING")
fmt.Printf("Running job %s\n", job.ID.String())
job.Run()