From e33cd5b49160b486c30b23784f8346fcb8fedcf8 Mon Sep 17 00:00:00 2001 From: Dean Karn Date: Wed, 1 Jun 2022 11:48:48 -0700 Subject: [PATCH 1/2] fix retryable in Next poller --- client.go | 20 ++++++++++---------- consumer/consumer.go | 23 +---------------------- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/client.go b/client.go index 036d101..c15514b 100644 --- a/client.go +++ b/client.go @@ -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) } } } diff --git a/consumer/consumer.go b/consumer/consumer.go index e9492f8..a557ff9 100644 --- a/consumer/consumer.go +++ b/consumer/consumer.go @@ -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 - } -} From abe5ab47d22de770533c97db4064091e67d0da27 Mon Sep 17 00:00:00 2001 From: Dean Karn Date: Wed, 1 Jun 2022 11:54:38 -0700 Subject: [PATCH 2/2] update to latest errors dep --- go.mod | 2 +- go.sum | 22 ++-------------------- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index b2791f8..e507e26 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/go-playground/backoff-sys v1.1.1 - github.com/go-playground/errors/v5 v5.1.1 + github.com/go-playground/errors/v5 v5.2.3 github.com/go-playground/pkg/v5 v5.6.0 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c ) diff --git a/go.sum b/go.sum index 9d64ae9..70b84b6 100644 --- a/go.sum +++ b/go.sum @@ -1,30 +1,12 @@ -github.com/aws/aws-sdk-go v1.32.11/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-playground/assert v1.2.1 h1:ad06XqC+TOv0nJWnbULSlh3ehp5uLuQEojZY5Tq8RgI= -github.com/go-playground/assert v1.2.1/go.mod h1:Lgy+k19nOB/wQG/fVSQ7rra5qYugmytMQqvQ2dgjWn8= github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/backoff-sys v1.1.1 h1:wlzbS+239Px9AK8EtdG27lUvbX7AssIxFLYrZAud5KA= github.com/go-playground/backoff-sys v1.1.1/go.mod h1:v6FlV3rjJ/qeUH0MEpypQGrVaQfqW5FSv9D+nXI68bY= -github.com/go-playground/errors/v5 v5.1.1 h1:H/igfatbYnCqa4Xednb1nnxljpPWnogA4TgsA4U891I= -github.com/go-playground/errors/v5 v5.1.1/go.mod h1:xyrVVz3LrfHZQmZQ1ri/8rdiis2F96q15wGX89xWsL0= -github.com/go-playground/form/v4 v4.1.1/go.mod h1:q1a2BY+AQUUzhl6xA/6hBetay6dEIhMHjgvJiGo6K7U= +github.com/go-playground/errors/v5 v5.2.3 h1:RPxaFHgJZjgk/OFkUcfytJgRQKRINLtueVxgOdnfPpg= +github.com/go-playground/errors/v5 v5.2.3/go.mod h1:DincxRGwraWmq39TZDqtnOtHGOJ+AbNbO0OmBzX6MLw= github.com/go-playground/form/v4 v4.2.0 h1:N1wh+Goz61e6w66vo8vJkQt+uwZSoLz50kZPJWR8eic= github.com/go-playground/form/v4 v4.2.0/go.mod h1:q1a2BY+AQUUzhl6xA/6hBetay6dEIhMHjgvJiGo6K7U= -github.com/go-playground/pkg/v5 v5.0.0/go.mod h1:0380E0lsFB1POWFypOLL8tX2f0O1OBCBpSdVmEy4mg0= github.com/go-playground/pkg/v5 v5.6.0 h1:97YpRFzIcS5NFP2Uzxj8cPYz4zTuwweyXADYcA1KfUQ= github.com/go-playground/pkg/v5 v5.6.0/go.mod h1:TvZ2nNtNh6VfoNteY9ApA2BXt1ZwJliFZ4hzPAwLS9Y= -github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=