mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-01-23 05:52:15 +08:00
add left time for upload
This commit is contained in:
parent
7132342ed3
commit
6f45a8048d
@ -14,6 +14,7 @@
|
||||
package uploader
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -24,6 +25,7 @@ type (
|
||||
Uploaded() int64 // 已上传数据
|
||||
SpeedsPerSecond() int64 // 每秒的上传速度
|
||||
TimeElapsed() time.Duration // 上传时间
|
||||
TimeLeft() time.Duration // 预计剩余时间, 负数代表未知
|
||||
}
|
||||
|
||||
// UploadStatus 上传状态
|
||||
@ -67,6 +69,18 @@ func (us *UploadStatus) TimeElapsed() time.Duration {
|
||||
return us.timeElapsed
|
||||
}
|
||||
|
||||
// TimeLeft 返回预计剩余时间, 负数代表未知
|
||||
func (us *UploadStatus) TimeLeft() time.Duration {
|
||||
var left time.Duration
|
||||
speeds := atomic.LoadInt64(&us.speedsPerSecond)
|
||||
if speeds <= 0 {
|
||||
left = -1
|
||||
} else {
|
||||
left = time.Duration((us.totalSize-us.uploaded)/(speeds)) * time.Second
|
||||
}
|
||||
return left
|
||||
}
|
||||
|
||||
// GetStatusChan 获取上传状态
|
||||
func (u *Uploader) GetStatusChan() <-chan Status {
|
||||
c := make(chan Status)
|
||||
|
@ -183,14 +183,23 @@ func (utu *UploadTaskUnit) upload() (result *taskframework.TaskUnitRunResult) {
|
||||
}
|
||||
|
||||
if utu.ShowProgress {
|
||||
// 如果下载速度为0, 剩余下载时间未知, 则用 - 代替
|
||||
var leftStr string
|
||||
left := status.TimeLeft()
|
||||
if left < 0 {
|
||||
leftStr = "-"
|
||||
} else {
|
||||
leftStr = left.String()
|
||||
}
|
||||
uploadedPercentage := fmt.Sprintf("%.2f%%", float64(status.Uploaded())/float64(status.TotalSize())*100)
|
||||
fmt.Printf("\r[%s] ↑ %s/%s(%s) %s/s(%s/s) in %s ............", utu.taskInfo.Id(),
|
||||
fmt.Printf("\r[%s] ↑ %s/%s(%s) %s/s(%s/s) in %s, left %s ............", utu.taskInfo.Id(),
|
||||
converter.ConvertFileSize(status.Uploaded(), 2),
|
||||
converter.ConvertFileSize(status.TotalSize(), 2),
|
||||
uploadedPercentage,
|
||||
converter.ConvertFileSize(status.SpeedsPerSecond(), 2),
|
||||
converter.ConvertFileSize(utu.GlobalSpeedsStat.GetSpeeds(), 2),
|
||||
status.TimeElapsed(),
|
||||
leftStr,
|
||||
)
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user