jobqueue: Replace JobArgs() with Job()
JobArgs() function replaced with more general Job() function that returns all the parameters used to originally define a job during Enqueue(). This new function enables access to the type of a job in the queue, which wasn't available until now (except when Dequeueing).
This commit is contained in:
parent
75a96bd99d
commit
668fb003ef
6 changed files with 26 additions and 18 deletions
|
|
@ -121,19 +121,18 @@ func (s *Server) JobStatus(id uuid.UUID, result interface{}) (*JobStatus, []uuid
|
|||
}, deps, nil
|
||||
}
|
||||
|
||||
// JobArgs provides access to the arguments of a job.
|
||||
func (s *Server) JobArgs(id uuid.UUID, jobArgs interface{}) (json.RawMessage, error) {
|
||||
rawArgs, err := s.jobs.JobArgs(id)
|
||||
// Job provides access to all the parameters of a job.
|
||||
func (s *Server) Job(id uuid.UUID, job interface{}) (string, json.RawMessage, []uuid.UUID, error) {
|
||||
jobType, rawArgs, deps, err := s.jobs.Job(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", nil, nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(rawArgs, jobArgs)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error unmarshaling arguments for job '%s': %v", id, err)
|
||||
if err := json.Unmarshal(rawArgs, job); err != nil {
|
||||
return "", nil, nil, fmt.Errorf("error unmarshaling arguments for job '%s': %v", id, err)
|
||||
}
|
||||
|
||||
return rawArgs, nil
|
||||
return jobType, rawArgs, deps, nil
|
||||
}
|
||||
|
||||
func (s *Server) Cancel(id uuid.UUID) error {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
|
|
@ -198,10 +199,12 @@ func TestArgs(t *testing.T) {
|
|||
require.NotNil(t, args)
|
||||
|
||||
var jobArgs worker.OSBuildJob
|
||||
rawArgs, err := server.JobArgs(jobId, &jobArgs)
|
||||
jobType, rawArgs, deps, err := server.Job(jobId, &jobArgs)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, args, rawArgs)
|
||||
require.Equal(t, job, jobArgs)
|
||||
require.Equal(t, jobType, "osbuild:"+arch.Name())
|
||||
require.Equal(t, []uuid.UUID(nil), deps)
|
||||
}
|
||||
|
||||
func TestUpload(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue