rc: add execute-id for job-id

This commit is contained in:
yuudi 2023-06-28 12:06:36 -04:00 committed by Nick Craig-Wood
parent 10449c86a4
commit 5b63b9534f
2 changed files with 24 additions and 6 deletions

View File

@ -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
}

View File

@ -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) {