diff --git a/fs/rc/jobs/job.go b/fs/rc/jobs/job.go index 1cdfd91e0..3444178b0 100644 --- a/fs/rc/jobs/job.go +++ b/fs/rc/jobs/job.go @@ -10,6 +10,7 @@ import ( "sync/atomic" "time" + "github.com/google/uuid" "github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs/accounting" "github.com/rclone/rclone/fs/cache" @@ -120,8 +121,9 @@ type Jobs struct { } var ( - running = newJobs() - jobID = int64(0) + running = newJobs() + jobID = int64(0) + executeID = uuid.New().String() ) // newJobs makes a new Jobs structure @@ -403,7 +405,8 @@ func init() { Results: -- jobids - array of integer job ids. +- executeId - string id of rclone executing (change after restart) +- jobids - array of integer job ids (starting at 1 on each restart) `, }) } @@ -412,6 +415,7 @@ Results: func rcJobList(ctx context.Context, in rc.Params) (out rc.Params, err error) { out = make(rc.Params) out["jobids"] = running.IDs() + out["executeId"] = executeID return out, nil } diff --git a/fs/rc/jobs/job_test.go b/fs/rc/jobs/job_test.go index 2fa6ff4f3..3fa45a471 100644 --- a/fs/rc/jobs/job_test.go +++ b/fs/rc/jobs/job_test.go @@ -374,10 +374,24 @@ func TestRcJobList(t *testing.T) { call := rc.Calls.Get("job/list") assert.NotNil(t, call) in := rc.Params{} - out, err := call.Fn(context.Background(), in) + out1, err := call.Fn(context.Background(), in) require.NoError(t, err) - require.NotNil(t, out) - assert.Equal(t, rc.Params{"jobids": []int64{1}}, out) + require.NotNil(t, out1) + assert.Equal(t, []int64{1}, out1["jobids"], "should have job listed") + + _, _, err = NewJob(ctx, longFn, rc.Params{"_async": true}) + assert.NoError(t, err) + + call = rc.Calls.Get("job/list") + assert.NotNil(t, call) + in = rc.Params{} + out2, err := call.Fn(context.Background(), in) + require.NoError(t, err) + require.NotNil(t, out2) + assert.Equal(t, 2, len(out2["jobids"].([]int64)), "should have all jobs listed") + + require.NotNil(t, out1["executeId"], "should have executeId") + assert.Equal(t, out1["executeId"], out2["executeId"], "executeId should be the same") } func TestRcAsyncJobStop(t *testing.T) {