Skip to content

Add retry on recoverable exception for the backend#6122

Merged
auvipy merged 5 commits into
celery:masterfrom
criteo-forks:safe_backend_retry
Jun 1, 2020
Merged

Add retry on recoverable exception for the backend#6122
auvipy merged 5 commits into
celery:masterfrom
criteo-forks:safe_backend_retry

Conversation

@mchataigner

Copy link
Copy Markdown
Contributor

acks.late makes celery acknowledge messages only after processing and
storing result on the backend.

However, in case of backend unreachable, it will shadow a Retry
exception and put the task as failed in the backend not retrying the
task and acknoledging it on the broker.

With this new result_backend_always_retry setting, if the backend
exception is recoverable (to be defined per backend implementation),
it will retry the backend operation with an exponential backoff.

In addition, make ES retry storing updates in a better way

if existing value in the backend is success, then do nothing.
if it is a ready status, then update it only if new value is a ready status as well.
else update it.

This way, a SUCCESS cannot be overriden so that we do not loose
results but any ready state other than success (FAILURE, REVOKED) can
be overriden by another ready status (i.e. a SUCCESS)

@lgtm-com

lgtm-com Bot commented May 27, 2020

Copy link
Copy Markdown

This pull request introduces 3 alerts and fixes 2 when merging bfe7785 into 704896a - view on LGTM.com

new alerts:

  • 2 for Module is imported with 'import' and 'import from'
  • 1 for Non-exception in 'except' clause

fixed alerts:

  • 2 for Module is imported with 'import' and 'import from'

@mchataigner
mchataigner force-pushed the safe_backend_retry branch from bfe7785 to 1e20ea9 Compare May 27, 2020 16:40
@lgtm-com

lgtm-com Bot commented May 27, 2020

Copy link
Copy Markdown

This pull request fixes 2 alerts when merging 1e20ea9 into 704896a - view on LGTM.com

fixed alerts:

  • 2 for Module is imported with 'import' and 'import from'

@mchataigner
mchataigner force-pushed the safe_backend_retry branch from 1e20ea9 to 3b06404 Compare May 27, 2020 19:10
@codecov

codecov Bot commented May 27, 2020

Copy link
Copy Markdown

Codecov Report

Merging #6122 into master will decrease coverage by 0.16%.
The diff coverage is 48.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6122      +/-   ##
==========================================
- Coverage   83.36%   83.19%   -0.17%     
==========================================
  Files         145      145              
  Lines       17283    17318      +35     
  Branches     2141     2147       +6     
==========================================
  Hits        14408    14408              
- Misses       2651     2686      +35     
  Partials      224      224              
Impacted Files Coverage Δ
celery/app/defaults.py 95.50% <ø> (ø)
celery/exceptions.py 28.88% <0.00%> (-5.33%) ⬇️
celery/backends/elasticsearch.py 66.10% <27.27%> (-3.27%) ⬇️
celery/backends/base.py 93.03% <54.05%> (-2.80%) ⬇️
celery/backends/arangodb.py 50.00% <100.00%> (-4.63%) ⬇️
celery/backends/azureblockblob.py 98.18% <100.00%> (ø)
celery/backends/cache.py 100.00% <100.00%> (ø)
celery/backends/consul.py 67.27% <100.00%> (ø)
celery/backends/cosmosdbsql.py 92.00% <100.00%> (ø)
celery/backends/couchbase.py 80.26% <100.00%> (ø)
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2479f95...6c098b5. Read the comment docs.

@lgtm-com

lgtm-com Bot commented May 27, 2020

Copy link
Copy Markdown

This pull request introduces 2 alerts and fixes 3 when merging 3b06404 into 704896a - view on LGTM.com

new alerts:

  • 2 for Module is imported with 'import' and 'import from'

fixed alerts:

  • 2 for Module is imported with 'import' and 'import from'
  • 1 for Non-exception in 'except' clause

@auvipy auvipy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job so far! can you increase the coverage bit more?

@auvipy auvipy added this to the 4.4.x milestone May 27, 2020
@mchataigner
mchataigner force-pushed the safe_backend_retry branch from 3b06404 to 6c098b5 Compare June 1, 2020 19:10
@lgtm-com

lgtm-com Bot commented Jun 1, 2020

Copy link
Copy Markdown

This pull request fixes 4 alerts when merging 6c098b5 into 52aef4b - view on LGTM.com

fixed alerts:

  • 4 for Module is imported with 'import' and 'import from'

This way, a backend implementation is able to take decisions based on
current state to store meta in case of failures.
@mchataigner
mchataigner force-pushed the safe_backend_retry branch from 6c098b5 to 752dab5 Compare June 1, 2020 22:48
@lgtm-com

lgtm-com Bot commented Jun 1, 2020

Copy link
Copy Markdown

This pull request introduces 2 alerts and fixes 4 when merging 752dab5 into 52aef4b - view on LGTM.com

new alerts:

  • 1 for Non-exception in 'except' clause
  • 1 for Wrong number of arguments in a call

fixed alerts:

  • 4 for Module is imported with 'import' and 'import from'

Mathieu Chataigner added 4 commits June 2, 2020 01:09
acks.late makes celery acknowledge messages only after processing and
storing result on the backend.

However, in case of backend unreachable, it will shadow a Retry
exception and put the task as failed in the backend not retrying the
task and acknoledging it on the broker.

With this new result_backend_always_retry setting, if the backend
exception is recoverable (to be defined per backend implementation),
it will retry the backend operation with an exponential backoff.
if existing value in the backend is success, then do nothing.
if it is a ready status, then update it only if new value is a ready status as well.
else update it.

This way, a SUCCESS cannot be overriden so that we do not loose
results but any ready state other than success (FAILURE, REVOKED) can
be overriden by another ready status (i.e. a SUCCESS)
@auvipy

auvipy commented Jun 1, 2020

Copy link
Copy Markdown
Member

flake8 issues need to be fixed

@mchataigner
mchataigner force-pushed the safe_backend_retry branch from 752dab5 to 4e9815c Compare June 1, 2020 23:19
@mchataigner

Copy link
Copy Markdown
Contributor Author

Done.

@auvipy
auvipy merged commit 0463bff into celery:master Jun 1, 2020
@lgtm-com

lgtm-com Bot commented Jun 1, 2020

Copy link
Copy Markdown

This pull request introduces 2 alerts when merging 4e9815c into d3863d9 - view on LGTM.com

new alerts:

  • 1 for Non-exception in 'except' clause
  • 1 for Module is imported with 'import' and 'import from'