Skip to content

Commit a4d579e

Browse files
authored
Builds: fix retry (#9133)
We can't rely on `autoretry_for` for exceptions that are raised inside the `before_start` handler. How autoretry_for works is that it wraps the run method to catch the exceptionhttps://github.com/celery/celery/blob/ab2bcc096a9013a9147a3be1a2699d2312f93d1f/celery/app/autoretry.py#L29-L34But celery calls before_start separately from runhttps://github.com/celery/celery/blob/ab2bcc096a9013a9147a3be1a2699d2312f93d1f/celery/app/trace.py#L445-L448 Closes #9014
1 parent 9241a9e commit a4d579e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

readthedocs/projects/tasks/builds.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,15 @@ def _check_concurrency_limit(self):
296296
max_concurrent_builds = settings.RTD_MAX_CONCURRENT_BUILDS
297297

298298
if concurrency_limit_reached:
299-
# By raising this exception and using ``autoretry_for``, Celery
300-
# will handle this automatically calling ``on_retry``
299+
# By calling ``retry`` Celery will raise an exception and call ``on_retry``.
300+
# NOTE: autoretry_for doesn't work with exceptions raised from before_start,
301+
# it only works if they are raised from the run/execute method.
301302
log.info("Concurrency limit reached, retrying task.")
302-
raise BuildMaxConcurrencyError(
303-
BuildMaxConcurrencyError.message.format(
304-
limit=max_concurrent_builds,
303+
self.retry(
304+
exc=BuildMaxConcurrencyError(
305+
BuildMaxConcurrencyError.message.format(
306+
limit=max_concurrent_builds,
307+
)
305308
)
306309
)
307310

0 commit comments

Comments
 (0)