|
31 | 31 | BUILD_STATE_CLONING,
|
32 | 32 | BUILD_STATE_FINISHED,
|
33 | 33 | BUILD_STATE_INSTALLING,
|
| 34 | + BUILD_STATE_TRIGGERED, |
34 | 35 | BUILD_STATE_UPLOADING,
|
35 | 36 | BUILD_STATUS_FAILURE,
|
36 | 37 | BUILD_STATUS_SUCCESS,
|
@@ -218,8 +219,9 @@ class UpdateDocsTask(SyncRepositoryMixin, Task):
|
218 | 219 | autoretry_for = (
|
219 | 220 | BuildMaxConcurrencyError,
|
220 | 221 | )
|
221 |
| - max_retries = 5 # 5 per normal builds, 25 per concurrency limited |
222 |
| - default_retry_delay = 7 * 60 |
| 222 | + max_retries = settings.RTD_BUILDS_MAX_RETRIES |
| 223 | + default_retry_delay = settings.RTD_BUILDS_RETRY_DELAY |
| 224 | + retry_backoff = False |
223 | 225 |
|
224 | 226 | # Expected exceptions that will be logged as info only and not retried.
|
225 | 227 | # These exceptions are not sent to Sentry either because we are using
|
@@ -279,25 +281,12 @@ def _check_concurrency_limit(self):
|
279 | 281 | max_concurrent_builds = settings.RTD_MAX_CONCURRENT_BUILDS
|
280 | 282 |
|
281 | 283 | if concurrency_limit_reached:
|
282 |
| - # TODO: this could be handled in `on_retry` probably |
283 |
| - log.warning( |
284 |
| - 'Delaying tasks due to concurrency limit.', |
285 |
| - project_slug=self.data.project.slug, |
286 |
| - version_slug=self.data.version.slug, |
287 |
| - ) |
288 |
| - |
289 |
| - # This is done automatically on the environment context, but |
290 |
| - # we are executing this code before creating one |
291 |
| - api_v2.build(self.data.build['id']).patch({ |
292 |
| - 'error': BuildMaxConcurrencyError.message.format( |
| 284 | + # By raising this exception and using ``autoretry_for``, Celery |
| 285 | + # will handle this automatically calling ``on_retry`` |
| 286 | + raise BuildMaxConcurrencyError( |
| 287 | + BuildMaxConcurrencyError.message.format( |
293 | 288 | limit=max_concurrent_builds,
|
294 |
| - ), |
295 |
| - 'builder': socket.gethostname(), |
296 |
| - }) |
297 |
| - self.retry( |
298 |
| - exc=BuildMaxConcurrencyError, |
299 |
| - # We want to retry this build more times |
300 |
| - max_retries=25, |
| 289 | + ) |
301 | 290 | )
|
302 | 291 |
|
303 | 292 | def _check_duplicated_build(self):
|
@@ -499,7 +488,25 @@ def on_success(self, retval, task_id, args, kwargs):
|
499 | 488 | self.data.build['success'] = True
|
500 | 489 |
|
501 | 490 | def on_retry(self, exc, task_id, args, kwargs, einfo):
|
502 |
| - log.warning('Retrying this task.') |
| 491 | + """ |
| 492 | + Celery helper called when the task is retried. |
| 493 | +
|
| 494 | + This happens when any of the exceptions defined in ``autoretry_for`` |
| 495 | + argument is raised or when ``self.retry`` is called from inside the |
| 496 | + task. |
| 497 | +
|
| 498 | + See https://docs.celeryproject.org/en/master/userguide/tasks.html#retrying |
| 499 | + """ |
| 500 | + log.info('Retrying this task.') |
| 501 | + |
| 502 | + if isinstance(exc, BuildMaxConcurrencyError): |
| 503 | + log.warning( |
| 504 | + 'Delaying tasks due to concurrency limit.', |
| 505 | + project_slug=self.data.project.slug, |
| 506 | + version_slug=self.data.version.slug, |
| 507 | + ) |
| 508 | + self.data.build['error'] = exc.message |
| 509 | + self.update_build(state=BUILD_STATE_TRIGGERED) |
503 | 510 |
|
504 | 511 | def after_return(self, status, retval, task_id, args, kwargs, einfo):
|
505 | 512 | # Update build object
|
|
0 commit comments