Skip to content

Commit c217a2a

Browse files
committed
fix: invalid timeout context in puller
1 parent ea850c8 commit c217a2a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

service/pull/pull.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,28 @@ func NewPuller(feedRepo FeedRepo, itemRepo ItemRepo) *Puller {
3434
}
3535
}
3636

37+
const interval = 30
38+
3739
func (p *Puller) Run() {
38-
const interval = 30
39-
ctx, cancel := context.WithTimeout(context.Background(), (interval-3)*time.Minute)
40+
ctx, cancel := context.WithCancel(context.Background())
4041
defer cancel()
4142
ticker := time.NewTicker(interval * time.Minute)
4243
defer ticker.Stop()
4344

4445
for {
46+
p.PullAll(ctx)
47+
4548
select {
4649
case <-ctx.Done():
4750
return
4851
case <-ticker.C:
4952
}
50-
51-
p.PullAll(ctx)
5253
}
5354
}
5455

5556
func (p *Puller) PullAll(ctx context.Context) error {
5657
log.Println("start pull-all")
57-
ctx, cancel := context.WithTimeout(ctx, 5*time.Minute)
58+
ctx, cancel := context.WithTimeout(ctx, (interval-3)*time.Minute)
5859
defer cancel()
5960
feeds, err := p.feedRepo.All()
6061
if err != nil {

0 commit comments

Comments
 (0)