Skip to content

Commit

Permalink
refractor: downloader task action dispatch (GopeedLab#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie authored Oct 24, 2023
1 parent ff6c0da commit 11befc0
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 195 deletions.
8 changes: 5 additions & 3 deletions internal/protocol/http/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ func (f *Fetcher) fetchChunk(index int, ctx context.Context) (err error) {
return nil
}()
if err != nil {
// If canceled, do not retry
if errors.Is(err, context.Canceled) {
return
}
// retry request after 1 second
chunk.retryTimes = chunk.retryTimes + 1
time.Sleep(time.Second)
Expand Down Expand Up @@ -466,9 +470,7 @@ func (fb *FetcherBuilder) Restore() (v any, f func(meta *fetcher.FetcherMeta, v
fetcher.meta = meta
base.ParseReqExtra[fhttp.ReqExtra](fetcher.meta.Req)
base.ParseOptsExtra[fhttp.OptsExtra](fetcher.meta.Opts)
if len(fd.Chunks) == 0 {
fetcher.chunks = fetcher.splitChunk()
} else {
if len(fd.Chunks) > 0 {
fetcher.chunks = fd.Chunks
}
return fetcher
Expand Down
Loading

0 comments on commit 11befc0

Please sign in to comment.