worker: generalize job types in the server
The worker server was heavily tied to OSBuildJob(Result). Untie it so that it can deal with different job types in the future. This necessitates a change in the jobqueue: Dequeue() now returns the job type, as well as job arguments as json.RawMessage. This is so that the server can wait on multiple job types with different argument types. The weldr, composer, and koji APIs continue to use only "osbuild" jobs.
This commit is contained in:
parent
6b6cd7ca9f
commit
59e73a686a
9 changed files with 108 additions and 85 deletions
|
|
@ -145,13 +145,13 @@ func (q *fsJobQueue) Enqueue(jobType string, args interface{}, dependencies []uu
|
|||
return j.Id, nil
|
||||
}
|
||||
|
||||
func (q *fsJobQueue) Dequeue(ctx context.Context, jobTypes []string, args interface{}) (uuid.UUID, error) {
|
||||
func (q *fsJobQueue) Dequeue(ctx context.Context, jobTypes []string) (uuid.UUID, string, json.RawMessage, error) {
|
||||
q.mu.Lock()
|
||||
defer q.mu.Unlock()
|
||||
|
||||
// Return early if the context is already canceled.
|
||||
if err := ctx.Err(); err != nil {
|
||||
return uuid.Nil, err
|
||||
return uuid.Nil, "", nil, err
|
||||
}
|
||||
|
||||
// Filter q.pending by the `jobTypes`. Ignore those job types that this
|
||||
|
|
@ -173,12 +173,12 @@ func (q *fsJobQueue) Dequeue(ctx context.Context, jobTypes []string, args interf
|
|||
q.mu.Lock()
|
||||
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
return uuid.Nil, "", nil, err
|
||||
}
|
||||
|
||||
j, err = q.readJob(id)
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
return uuid.Nil, "", nil, err
|
||||
}
|
||||
|
||||
if !j.Canceled {
|
||||
|
|
@ -186,19 +186,14 @@ func (q *fsJobQueue) Dequeue(ctx context.Context, jobTypes []string, args interf
|
|||
}
|
||||
}
|
||||
|
||||
err := json.Unmarshal(j.Args, args)
|
||||
if err != nil {
|
||||
return uuid.Nil, fmt.Errorf("error unmarshaling arguments for job '%s': %v", j.Id, err)
|
||||
}
|
||||
|
||||
j.StartedAt = time.Now()
|
||||
|
||||
err = q.db.Write(j.Id.String(), j)
|
||||
err := q.db.Write(j.Id.String(), j)
|
||||
if err != nil {
|
||||
return uuid.Nil, fmt.Errorf("error writing job %s: %v", j.Id, err)
|
||||
return uuid.Nil, "", nil, fmt.Errorf("error writing job %s: %v", j.Id, err)
|
||||
}
|
||||
|
||||
return j.Id, nil
|
||||
return j.Id, j.Type, j.Args, nil
|
||||
}
|
||||
|
||||
func (q *fsJobQueue) FinishJob(id uuid.UUID, result interface{}) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue