@@ -13,36 +13,34 @@ var _ Downloader = &RetryDownloader{}
13
13
// RetryDownloader retry the downloads
14
14
type RetryDownloader struct {
15
15
Downloader
16
- ctx context.Context
17
16
RetryTimes int // the total execute times
18
17
RetryDelay int // time to delay seconds
19
18
}
20
19
21
20
// 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 {
23
22
return & RetryDownloader {
24
23
Downloader : downloader ,
25
- ctx : ctx ,
26
24
RetryTimes : retryTimes ,
27
25
RetryDelay : retryDelay ,
28
26
}
29
27
}
30
28
31
- func (d * RetryDownloader ) retry (work func () error ) error {
29
+ func (d * RetryDownloader ) retry (ctx context. Context , work func (context. Context ) error ) error {
32
30
var (
33
31
times = d .RetryTimes
34
32
err error
35
33
)
36
34
for ; times > 0 ; times -- {
37
- if err = work (); err == nil {
35
+ if err = work (ctx ); err == nil {
38
36
return nil
39
37
}
40
38
if IsErrNotSupported (err ) {
41
39
return err
42
40
}
43
41
select {
44
- case <- d . ctx .Done ():
45
- return d . ctx .Err ()
42
+ case <- ctx .Done ():
43
+ return ctx .Err ()
46
44
case <- time .After (time .Second * time .Duration (d .RetryDelay )):
47
45
}
48
46
}
@@ -56,7 +54,7 @@ func (d *RetryDownloader) GetRepoInfo(ctx context.Context) (*Repository, error)
56
54
err error
57
55
)
58
56
59
- err = d .retry (func () error {
57
+ err = d .retry (ctx , func (ctx context. Context ) error {
60
58
repo , err = d .Downloader .GetRepoInfo (ctx )
61
59
return err
62
60
})
@@ -71,7 +69,7 @@ func (d *RetryDownloader) GetTopics(ctx context.Context) ([]string, error) {
71
69
err error
72
70
)
73
71
74
- err = d .retry (func () error {
72
+ err = d .retry (ctx , func (ctx context. Context ) error {
75
73
topics , err = d .Downloader .GetTopics (ctx )
76
74
return err
77
75
})
@@ -86,7 +84,7 @@ func (d *RetryDownloader) GetMilestones(ctx context.Context) ([]*Milestone, erro
86
84
err error
87
85
)
88
86
89
- err = d .retry (func () error {
87
+ err = d .retry (ctx , func (ctx context. Context ) error {
90
88
milestones , err = d .Downloader .GetMilestones (ctx )
91
89
return err
92
90
})
@@ -101,7 +99,7 @@ func (d *RetryDownloader) GetReleases(ctx context.Context) ([]*Release, error) {
101
99
err error
102
100
)
103
101
104
- err = d .retry (func () error {
102
+ err = d .retry (ctx , func (ctx context. Context ) error {
105
103
releases , err = d .Downloader .GetReleases (ctx )
106
104
return err
107
105
})
@@ -116,7 +114,7 @@ func (d *RetryDownloader) GetLabels(ctx context.Context) ([]*Label, error) {
116
114
err error
117
115
)
118
116
119
- err = d .retry (func () error {
117
+ err = d .retry (ctx , func (ctx context. Context ) error {
120
118
labels , err = d .Downloader .GetLabels (ctx )
121
119
return err
122
120
})
@@ -132,7 +130,7 @@ func (d *RetryDownloader) GetIssues(ctx context.Context, page, perPage int) ([]*
132
130
err error
133
131
)
134
132
135
- err = d .retry (func () error {
133
+ err = d .retry (ctx , func (ctx context. Context ) error {
136
134
issues , isEnd , err = d .Downloader .GetIssues (ctx , page , perPage )
137
135
return err
138
136
})
@@ -148,7 +146,7 @@ func (d *RetryDownloader) GetComments(ctx context.Context, commentable Commentab
148
146
err error
149
147
)
150
148
151
- err = d .retry (func () error {
149
+ err = d .retry (ctx , func (context. Context ) error {
152
150
comments , isEnd , err = d .Downloader .GetComments (ctx , commentable )
153
151
return err
154
152
})
@@ -164,7 +162,7 @@ func (d *RetryDownloader) GetPullRequests(ctx context.Context, page, perPage int
164
162
isEnd bool
165
163
)
166
164
167
- err = d .retry (func () error {
165
+ err = d .retry (ctx , func (ctx context. Context ) error {
168
166
prs , isEnd , err = d .Downloader .GetPullRequests (ctx , page , perPage )
169
167
return err
170
168
})
@@ -178,7 +176,7 @@ func (d *RetryDownloader) GetReviews(ctx context.Context, reviewable Reviewable)
178
176
reviews []* Review
179
177
err error
180
178
)
181
- err = d .retry (func () error {
179
+ err = d .retry (ctx , func (ctx context. Context ) error {
182
180
reviews , err = d .Downloader .GetReviews (ctx , reviewable )
183
181
return err
184
182
})
0 commit comments