mirror of
https://github.com/restic/restic.git
synced 2024-12-23 16:26:11 +00:00
Update progress status when necessary
This commit is contained in:
parent
05e2afba0b
commit
9d1c03f56e
1 changed files with 19 additions and 8 deletions
11
progress.go
11
progress.go
|
@ -6,6 +6,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const minTickerTime = time.Second / 60
|
||||||
|
|
||||||
type Progress struct {
|
type Progress struct {
|
||||||
OnStart func()
|
OnStart func()
|
||||||
OnUpdate ProgressFunc
|
OnUpdate ProgressFunc
|
||||||
|
@ -19,6 +21,7 @@ type Progress struct {
|
||||||
cancel chan struct{}
|
cancel chan struct{}
|
||||||
o sync.Once
|
o sync.Once
|
||||||
d time.Duration
|
d time.Duration
|
||||||
|
lastUpdate time.Time
|
||||||
|
|
||||||
running bool
|
running bool
|
||||||
}
|
}
|
||||||
|
@ -92,9 +95,17 @@ func (p *Progress) Report(s Stat) {
|
||||||
p.curM.Lock()
|
p.curM.Lock()
|
||||||
p.cur.Add(s)
|
p.cur.Add(s)
|
||||||
cur := p.cur
|
cur := p.cur
|
||||||
|
needUpdate := false
|
||||||
|
if time.Since(p.lastUpdate) > minTickerTime {
|
||||||
|
p.lastUpdate = time.Now()
|
||||||
|
needUpdate = true
|
||||||
|
}
|
||||||
p.curM.Unlock()
|
p.curM.Unlock()
|
||||||
|
|
||||||
|
if needUpdate {
|
||||||
p.updateProgress(cur, false)
|
p.updateProgress(cur, false)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Progress) updateProgress(cur Stat, ticker bool) {
|
func (p *Progress) updateProgress(cur Stat, ticker bool) {
|
||||||
|
|
Loading…
Reference in a new issue