jobqueue: Add JobArgs() method
JobArgs() returns the arguments submitted with a job in raw form. Since the structure of the args are opaque to job queue, it's the responsibility of the caller to deserialize the arguments. Args retrieval is added to the existing TestArgs() function.
This commit is contained in:
parent
c03296b3f8
commit
6967333759
3 changed files with 26 additions and 0 deletions
|
|
@ -287,6 +287,16 @@ func (q *fsJobQueue) JobStatus(id uuid.UUID) (result json.RawMessage, queued, st
|
|||
return
|
||||
}
|
||||
|
||||
func (q *fsJobQueue) JobArgs(id uuid.UUID) (args json.RawMessage, err error) {
|
||||
j, err := q.readJob(id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
args = j.Args
|
||||
return
|
||||
}
|
||||
|
||||
// Reads job with `id`. This is a thin wrapper around `q.db.Read`, which
|
||||
// returns the job directly, or and error if a job with `id` does not exist.
|
||||
func (q *fsJobQueue) readJob(id uuid.UUID) (*job, error) {
|
||||
|
|
|
|||
|
|
@ -103,6 +103,11 @@ func TestArgs(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, twoargs, parsedArgs)
|
||||
|
||||
// Read args after Dequeue
|
||||
jargs, err := q.JobArgs(id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, args, jargs)
|
||||
|
||||
id, deps, typ, args, err = q.Dequeue(context.Background(), []string{"fish"})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, one, id)
|
||||
|
|
@ -111,6 +116,14 @@ func TestArgs(t *testing.T) {
|
|||
err = json.Unmarshal(args, &parsedArgs)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, oneargs, parsedArgs)
|
||||
|
||||
// Read args directly after Dequeue
|
||||
jargs, err = q.JobArgs(id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, args, jargs)
|
||||
|
||||
_, err = q.JobArgs(uuid.New())
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestJobTypes(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue