mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 17:14:44 +01:00
8243ff8bc8
Introduce stats groups that will isolate accounting for logically different transferring operations. That way multiple accounting operations can be done in parallel without interfering with each other stats. Using groups is optional. There is dedicated global stats that will be used by default if no group is specified. This is operating mode for CLI usage which is just fire and forget operation. For running rclone as rc http server each request will create it's own group. Also there is an option to specify your own group.
53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
package accounting
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/ncw/rclone/fs"
|
|
)
|
|
|
|
// inProgress holds a synchronized map of in progress transfers
|
|
type inProgress struct {
|
|
mu sync.Mutex
|
|
m map[string]*Account
|
|
}
|
|
|
|
// newInProgress makes a new inProgress object
|
|
func newInProgress() *inProgress {
|
|
return &inProgress{
|
|
m: make(map[string]*Account, fs.Config.Transfers),
|
|
}
|
|
}
|
|
|
|
// set marks the name as in progress
|
|
func (ip *inProgress) set(name string, acc *Account) {
|
|
ip.mu.Lock()
|
|
defer ip.mu.Unlock()
|
|
ip.m[name] = acc
|
|
}
|
|
|
|
// clear marks the name as no longer in progress
|
|
func (ip *inProgress) clear(name string) {
|
|
ip.mu.Lock()
|
|
defer ip.mu.Unlock()
|
|
delete(ip.m, name)
|
|
}
|
|
|
|
// get gets the account for name, of nil if not found
|
|
func (ip *inProgress) get(name string) *Account {
|
|
ip.mu.Lock()
|
|
defer ip.mu.Unlock()
|
|
return ip.m[name]
|
|
}
|
|
|
|
// merge adds items from another inProgress
|
|
func (ip *inProgress) merge(m *inProgress) {
|
|
ip.mu.Lock()
|
|
defer ip.mu.Unlock()
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
for key, val := range m.m {
|
|
ip.m[key] = val
|
|
}
|
|
}
|