mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-18 06:13:42 +00:00
Merge main into fix/deleted-task-lifecycle-1610
This commit is contained in:
commit
71999c0905
69 files changed
+1381
-260
No files matched your search
+55
-32
@@ -84,21 +84,24 @@ type Task struct {
|
||||
producer production.Source
|
||||
producerReceived int64
|
||||
|
||||
fetcherManager fetcher.FetcherManager
|
||||
fetcher fetcher.Fetcher
|
||||
timer *util.Timer
|
||||
statusLock *sync.Mutex
|
||||
lock *sync.Mutex
|
||||
statsLock *sync.Mutex
|
||||
statsLoaded bool
|
||||
stats *fetcher.Stats
|
||||
statsSnapshot json.RawMessage
|
||||
blobRefLock *sync.Mutex
|
||||
blobURL string
|
||||
runGeneration uint64
|
||||
lifetime *taskLifetime
|
||||
speedArr []int64
|
||||
uploadSpeedArr []int64
|
||||
fetcherManager fetcher.FetcherManager
|
||||
fetcher fetcher.Fetcher
|
||||
timer *util.Timer
|
||||
statusLock *sync.Mutex
|
||||
lock *sync.Mutex
|
||||
statsLock *sync.Mutex
|
||||
statsLoaded bool
|
||||
stats *fetcher.Stats
|
||||
statsSnapshot json.RawMessage
|
||||
blobRefLock *sync.Mutex
|
||||
blobURL string
|
||||
runGeneration uint64
|
||||
lifetime *taskLifetime
|
||||
speedArr []speedSample
|
||||
uploadSpeedArr []speedSample
|
||||
downloadSampledAt time.Time
|
||||
uploadSampledAt time.Time
|
||||
receivedBytes int64
|
||||
}
|
||||
|
||||
// TaskRuntimeStatus is the lightweight, frequently refreshed view of a task.
|
||||
@@ -206,7 +209,21 @@ func (t *Task) updateUploadSpeed(downloaded int64, usedTime float64) int64 {
|
||||
return calcSpeed(&t.uploadSpeedArr, downloaded, usedTime)
|
||||
}
|
||||
|
||||
func calcSpeed(speedArr *[]int64, downloaded int64, usedTime float64) int64 {
|
||||
type speedSample struct {
|
||||
bytes int64
|
||||
seconds float64
|
||||
}
|
||||
|
||||
func sampleSeconds(lastSample *time.Time, now time.Time) float64 {
|
||||
previous := *lastSample
|
||||
*lastSample = now
|
||||
if previous.IsZero() {
|
||||
return 0
|
||||
}
|
||||
return now.Sub(previous).Seconds()
|
||||
}
|
||||
|
||||
func calcSpeed(speedArr *[]speedSample, downloaded int64, usedTime float64) int64 {
|
||||
if usedTime <= 0 {
|
||||
return 0
|
||||
}
|
||||
@@ -215,18 +232,18 @@ func calcSpeed(speedArr *[]int64, downloaded int64, usedTime float64) int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
*speedArr = append(*speedArr, downloaded)
|
||||
// Record last 5 seconds of download speed to calculate the average speed
|
||||
if len(*speedArr) > int(5.0/usedTime) {
|
||||
*speedArr = (*speedArr)[1:]
|
||||
}
|
||||
|
||||
*speedArr = append(*speedArr, speedSample{bytes: downloaded, seconds: usedTime})
|
||||
var total int64
|
||||
for _, v := range *speedArr {
|
||||
total += v
|
||||
var elapsed float64
|
||||
first := len(*speedArr)
|
||||
for first > 0 && elapsed < 5 {
|
||||
first--
|
||||
sample := (*speedArr)[first]
|
||||
total += sample.bytes
|
||||
elapsed += sample.seconds
|
||||
}
|
||||
|
||||
return int64(float64(total) / float64(len(*speedArr)) / usedTime)
|
||||
*speedArr = (*speedArr)[first:]
|
||||
return int64(float64(total) / elapsed)
|
||||
}
|
||||
|
||||
type TaskFilter struct {
|
||||
@@ -243,12 +260,15 @@ type DownloaderConfig struct {
|
||||
Controller *controller.Controller
|
||||
FetchManagers []fetcher.FetcherManager
|
||||
|
||||
RefreshInterval int // RefreshInterval time duration to refresh task progress(ms)
|
||||
Storage Storage
|
||||
StorageDir string
|
||||
TempDir string
|
||||
WhiteDownloadDirs []string
|
||||
WebViewProvider enginewebview.Provider
|
||||
// ExtensionEventTimeout bounds one script load and its awaited event handler.
|
||||
// Zero uses one minute. Embedders may increase it for long-running handlers.
|
||||
ExtensionEventTimeout time.Duration
|
||||
RefreshInterval int // RefreshInterval time duration to refresh task progress(ms)
|
||||
Storage Storage
|
||||
StorageDir string
|
||||
TempDir string
|
||||
WhiteDownloadDirs []string
|
||||
WebViewProvider enginewebview.Provider
|
||||
|
||||
ProductionMode bool
|
||||
|
||||
@@ -271,6 +291,9 @@ func (cfg *DownloaderConfig) Init() *DownloaderConfig {
|
||||
new(ed2k.FetcherManager),
|
||||
}
|
||||
}
|
||||
if cfg.ExtensionEventTimeout <= 0 {
|
||||
cfg.ExtensionEventTimeout = time.Minute
|
||||
}
|
||||
if cfg.RefreshInterval == 0 {
|
||||
cfg.RefreshInterval = 350
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user