mirror of
https://github.com/rclone/rclone.git
synced 2025-12-06 00:03:32 +00:00
rc: add jobs stats
This commit is contained in:
@@ -189,6 +189,22 @@ func (jobs *Jobs) IDs() (IDs []int64) {
|
|||||||
return IDs
|
return IDs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stats returns the IDs of the running and finished jobs
|
||||||
|
func (jobs *Jobs) Stats() (running []int64, finished []int64) {
|
||||||
|
jobs.mu.RLock()
|
||||||
|
defer jobs.mu.RUnlock()
|
||||||
|
running = []int64{}
|
||||||
|
finished = []int64{}
|
||||||
|
for jobID := range jobs.jobs {
|
||||||
|
if jobs.jobs[jobID].Finished {
|
||||||
|
finished = append(finished, jobID)
|
||||||
|
} else {
|
||||||
|
running = append(running, jobID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return running, finished
|
||||||
|
}
|
||||||
|
|
||||||
// Get a job with a given ID or nil if it doesn't exist
|
// Get a job with a given ID or nil if it doesn't exist
|
||||||
func (jobs *Jobs) Get(ID int64) *Job {
|
func (jobs *Jobs) Get(ID int64) *Job {
|
||||||
jobs.mu.RLock()
|
jobs.mu.RLock()
|
||||||
@@ -409,6 +425,8 @@ Results:
|
|||||||
|
|
||||||
- executeId - string id of rclone executing (change after restart)
|
- executeId - string id of rclone executing (change after restart)
|
||||||
- jobids - array of integer job ids (starting at 1 on each restart)
|
- jobids - array of integer job ids (starting at 1 on each restart)
|
||||||
|
- running_ids - array of integer job ids that are running
|
||||||
|
- finished_ids - array of integer job ids that are finished
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -417,6 +435,9 @@ Results:
|
|||||||
func rcJobList(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
func rcJobList(ctx context.Context, in rc.Params) (out rc.Params, err error) {
|
||||||
out = make(rc.Params)
|
out = make(rc.Params)
|
||||||
out["jobids"] = running.IDs()
|
out["jobids"] = running.IDs()
|
||||||
|
runningIDs, finishedIDs := running.Stats()
|
||||||
|
out["running_ids"] = runningIDs
|
||||||
|
out["finished_ids"] = finishedIDs
|
||||||
out["executeId"] = executeID
|
out["executeId"] = executeID
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -378,6 +378,8 @@ func TestRcJobList(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, out1)
|
require.NotNil(t, out1)
|
||||||
assert.Equal(t, []int64{1}, out1["jobids"], "should have job listed")
|
assert.Equal(t, []int64{1}, out1["jobids"], "should have job listed")
|
||||||
|
assert.Equal(t, []int64{1}, out1["running_ids"], "should have running job")
|
||||||
|
assert.Equal(t, []int64{}, out1["finished_ids"], "should not have finished job")
|
||||||
|
|
||||||
_, _, err = NewJob(ctx, longFn, rc.Params{"_async": true})
|
_, _, err = NewJob(ctx, longFn, rc.Params{"_async": true})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user