Skip to content

Commit

Permalink
fix retryable in Next poller
Browse files Browse the repository at this point in the history
  • Loading branch information
deankarn committed Jun 1, 2022
1 parent 8284258 commit e33cd5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 32 deletions.
20 changes: 10 additions & 10 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,18 +236,18 @@ func (r *Client[P, S]) Next(ctx context.Context, queue string, num_jobs uint32)
return helpers, nil
default:

if resp.StatusCode >= 400 && resp.StatusCode < 500 {
return nil, errors.Newf("invalid request, status code: %d", resp.StatusCode)
if resp.StatusCode == http.StatusNoContent || httpext.IsRetryableStatusCode(resp.StatusCode) {
// includes http.StatusNoContent and http.TooManyRequests
// no new jobs to process
if err := r.nextBo.Sleep(ctx, attempt); err != nil {
// only context.Cancel as error ever
return nil, err
}
attempt++
continue
}

// includes http.StatusNoContent and http.TooManyRequests
// no new jobs to process
if err := r.nextBo.Sleep(ctx, attempt); err != nil {
// only context.Cancel as error ever
return nil, err
}
attempt++
continue
return nil, errors.Newf("invalid request, status code: %d", resp.StatusCode)
}
}
}
Expand Down
23 changes: 1 addition & 22 deletions consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,28 +206,7 @@ func (c *Consumer[P, S, T]) process(ctx context.Context, helper *relay.JobHelper
}

if c.autoComplete {
return c.complete(ctx, helper)
return helper.CompleteWithRetry(ctx)
}
return nil
}

func (c *Consumer[P, S, T]) complete(ctx context.Context, helper *relay.JobHelper[P, S]) (err error) {
var attempt int
for {
if attempt > 0 {
if err = c.bo.Sleep(ctx, attempt); err != nil {
// can only happen if context cancelled or timed out
return err
}
}
err = helper.Complete(ctx)
if err != nil {
if _, isRetryable := errorsext.IsRetryableHTTP(err); isRetryable {
attempt++
continue
}
return errors.Wrap(err, "failed to complete Job")
}
return nil
}
}

0 comments on commit e33cd5b

Please sign in to comment.