* rc/jobs: Add SetInitialJobID function that allows for setting the jobID

This commit is contained in:
Michal Matczuk 2019-08-21 12:01:39 +02:00 committed by Nick Craig-Wood
parent 82c6c77e07
commit 5d6593de4f

View File

@ -10,12 +10,10 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/rclone/rclone/fs/rc"
"github.com/rclone/rclone/fs/accounting"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/accounting"
"github.com/rclone/rclone/fs/rc"
) )
// Job describes a asynchronous task started via the rc package // Job describes a asynchronous task started via the rc package
@ -59,6 +57,13 @@ func SetOpt(opt *rc.Options) {
running.opt = opt running.opt = opt
} }
// SetInitialJobID allows for setting jobID before starting any jobs.
func SetInitialJobID(id int64) {
if !atomic.CompareAndSwapInt64(&jobID, 0, id) {
panic("Setting jobID is only possible before starting any jobs")
}
}
// kickExpire makes sure Expire is running // kickExpire makes sure Expire is running
func (jobs *Jobs) kickExpire() { func (jobs *Jobs) kickExpire() {
jobs.mu.Lock() jobs.mu.Lock()