Merge 81bb8b4941c06788a971011b20a688cf8dac03ea into 0b9671313b14ffe839ecbd7dd2ae5ac7f6f05db8

This commit is contained in:
n4n5 2025-04-11 15:06:37 +02:00 committed by GitHub
commit 187c55104b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View File

@ -184,6 +184,22 @@ func (jobs *Jobs) IDs() (IDs []int64) {
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
func (jobs *Jobs) Get(ID int64) *Job {
jobs.mu.RLock()
@ -404,6 +420,8 @@ Results:
- executeId - string id of rclone executing (change after 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
`,
})
}
@ -412,6 +430,9 @@ Results:
func rcJobList(ctx context.Context, in rc.Params) (out rc.Params, err error) {
out = make(rc.Params)
out["jobids"] = running.IDs()
runningIDs, finishedIDs := running.Stats()
out["running_ids"] = runningIDs
out["finished_ids"] = finishedIDs
out["executeId"] = executeID
return out, nil
}

View File

@ -377,6 +377,8 @@ func TestRcJobList(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, out1)
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})
assert.NoError(t, err)