Skip to content

Commit cc01d09

Browse files
Display real-time progress while transferring data (#467)
* Display real-time progress while transferring data * Restyled by gofmt Co-authored-by: Restyled.io <commits@restyled.io>
1 parent cd41ef3 commit cc01d09

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

task/common/machine/storage.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io"
99
"path/filepath"
1010
"strings"
11+
"time"
1112

1213
units "github.com/docker/go-units"
1314

@@ -17,6 +18,7 @@ import (
1718
_ "github.com/rclone/rclone/backend/s3"
1819

1920
"github.com/rclone/rclone/fs"
21+
"github.com/rclone/rclone/fs/accounting"
2022
"github.com/rclone/rclone/fs/filter"
2123
"github.com/rclone/rclone/fs/operations"
2224
"github.com/rclone/rclone/fs/sync"
@@ -130,6 +132,8 @@ func Transfer(ctx context.Context, source, destination string, include string) e
130132
return err
131133
}
132134

135+
defer progress(2 * time.Second)()
136+
133137
return sync.CopyDir(ctx, destinationFileSystem, sourceFileSystem, true)
134138
}
135139

@@ -159,3 +163,28 @@ func Delete(ctx context.Context, destination string) error {
159163

160164
return nil
161165
}
166+
167+
func progress(interval time.Duration) func() {
168+
accounting.GlobalStats().ResetCounters()
169+
ci := fs.GetConfig(context.Background())
170+
ci.StatsOneLine = true
171+
172+
ticker := time.NewTicker(interval)
173+
done := make(chan bool)
174+
175+
go func() {
176+
for {
177+
select {
178+
case <-ticker.C:
179+
logrus.Info(accounting.GlobalStats().String())
180+
case <-done:
181+
ticker.Stop()
182+
return
183+
}
184+
}
185+
}()
186+
187+
return func() {
188+
done <- true
189+
}
190+
}

0 commit comments

Comments
 (0)