Skip to content

Commit

Permalink
fix(tgb): poller blocking sleep, error not printing
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-linch committed Feb 25, 2024
1 parent 2cb340d commit 41b03ac
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tgb/polling.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,14 @@ func (poller *Poller) Run(ctx context.Context) error {

var offset int

defer func() {
poller.log("shutdown...")
poller.wg.Wait()
}()

for {
select {
case <-ctx.Done():
poller.log("shutdown...")
poller.wg.Wait()
return nil
default:

Expand All @@ -167,9 +170,14 @@ func (poller *Poller) Run(ctx context.Context) error {
updates, err := call.Do(ctx)

if err != nil && !errors.Is(err, context.Canceled) {
poller.log("error '%s' when getting updates, retrying in %v...", err, poller.retryAfter)

if poller.retryAfter > 0 {
poller.log("error getting updates, retrying in %v...", poller.retryAfter)
time.Sleep(poller.retryAfter)
select {
case <-time.After(poller.retryAfter):
case <-ctx.Done():
return nil
}
}
continue
}
Expand Down

0 comments on commit 41b03ac

Please sign in to comment.