@@ -13,36 +13,34 @@ var _ Downloader = &RetryDownloader{}
1313// RetryDownloader retry the downloads
1414type RetryDownloader struct {
1515 Downloader
16- ctx context.Context
1716 RetryTimes int // the total execute times
1817 RetryDelay int // time to delay seconds
1918}
2019
2120// NewRetryDownloader creates a retry downloader
22- func NewRetryDownloader (ctx context. Context , downloader Downloader , retryTimes , retryDelay int ) * RetryDownloader {
21+ func NewRetryDownloader (downloader Downloader , retryTimes , retryDelay int ) * RetryDownloader {
2322 return & RetryDownloader {
2423 Downloader : downloader ,
25- ctx : ctx ,
2624 RetryTimes : retryTimes ,
2725 RetryDelay : retryDelay ,
2826 }
2927}
3028
31- func (d * RetryDownloader ) retry (work func () error ) error {
29+ func (d * RetryDownloader ) retry (ctx context. Context , work func (context. Context ) error ) error {
3230 var (
3331 times = d .RetryTimes
3432 err error
3533 )
3634 for ; times > 0 ; times -- {
37- if err = work (); err == nil {
35+ if err = work (ctx ); err == nil {
3836 return nil
3937 }
4038 if IsErrNotSupported (err ) {
4139 return err
4240 }
4341 select {
44- case <- d . ctx .Done ():
45- return d . ctx .Err ()
42+ case <- ctx .Done ():
43+ return ctx .Err ()
4644 case <- time .After (time .Second * time .Duration (d .RetryDelay )):
4745 }
4846 }
@@ -56,7 +54,7 @@ func (d *RetryDownloader) GetRepoInfo(ctx context.Context) (*Repository, error)
5654 err error
5755 )
5856
59- err = d .retry (func () error {
57+ err = d .retry (ctx , func (ctx context. Context ) error {
6058 repo , err = d .Downloader .GetRepoInfo (ctx )
6159 return err
6260 })
@@ -71,7 +69,7 @@ func (d *RetryDownloader) GetTopics(ctx context.Context) ([]string, error) {
7169 err error
7270 )
7371
74- err = d .retry (func () error {
72+ err = d .retry (ctx , func (ctx context. Context ) error {
7573 topics , err = d .Downloader .GetTopics (ctx )
7674 return err
7775 })
@@ -86,7 +84,7 @@ func (d *RetryDownloader) GetMilestones(ctx context.Context) ([]*Milestone, erro
8684 err error
8785 )
8886
89- err = d .retry (func () error {
87+ err = d .retry (ctx , func (ctx context. Context ) error {
9088 milestones , err = d .Downloader .GetMilestones (ctx )
9189 return err
9290 })
@@ -101,7 +99,7 @@ func (d *RetryDownloader) GetReleases(ctx context.Context) ([]*Release, error) {
10199 err error
102100 )
103101
104- err = d .retry (func () error {
102+ err = d .retry (ctx , func (ctx context. Context ) error {
105103 releases , err = d .Downloader .GetReleases (ctx )
106104 return err
107105 })
@@ -116,7 +114,7 @@ func (d *RetryDownloader) GetLabels(ctx context.Context) ([]*Label, error) {
116114 err error
117115 )
118116
119- err = d .retry (func () error {
117+ err = d .retry (ctx , func (ctx context. Context ) error {
120118 labels , err = d .Downloader .GetLabels (ctx )
121119 return err
122120 })
@@ -132,7 +130,7 @@ func (d *RetryDownloader) GetIssues(ctx context.Context, page, perPage int) ([]*
132130 err error
133131 )
134132
135- err = d .retry (func () error {
133+ err = d .retry (ctx , func (ctx context. Context ) error {
136134 issues , isEnd , err = d .Downloader .GetIssues (ctx , page , perPage )
137135 return err
138136 })
@@ -148,7 +146,7 @@ func (d *RetryDownloader) GetComments(ctx context.Context, commentable Commentab
148146 err error
149147 )
150148
151- err = d .retry (func () error {
149+ err = d .retry (ctx , func (context. Context ) error {
152150 comments , isEnd , err = d .Downloader .GetComments (ctx , commentable )
153151 return err
154152 })
@@ -164,7 +162,7 @@ func (d *RetryDownloader) GetPullRequests(ctx context.Context, page, perPage int
164162 isEnd bool
165163 )
166164
167- err = d .retry (func () error {
165+ err = d .retry (ctx , func (ctx context. Context ) error {
168166 prs , isEnd , err = d .Downloader .GetPullRequests (ctx , page , perPage )
169167 return err
170168 })
@@ -178,7 +176,7 @@ func (d *RetryDownloader) GetReviews(ctx context.Context, reviewable Reviewable)
178176 reviews []* Review
179177 err error
180178 )
181- err = d .retry (func () error {
179+ err = d .retry (ctx , func (ctx context. Context ) error {
182180 reviews , err = d .Downloader .GetReviews (ctx , reviewable )
183181 return err
184182 })
0 commit comments