Context manager that catches connection errors and reconnects. Wraps a block of code so that any :attr:`_connection_errors` raised inside it trigger a call to :meth:`_reconnect`. If reconnection itself raises a connection error the consumer is considered unrecoverab
(self)
| 337 | |
| 338 | @contextmanager |
| 339 | def reconnect_on_error(self): |
| 340 | """Context manager that catches connection errors and reconnects. |
| 341 | |
| 342 | Wraps a block of code so that any :attr:`_connection_errors` raised |
| 343 | inside it trigger a call to :meth:`_reconnect`. If reconnection |
| 344 | itself raises a connection error the consumer is considered |
| 345 | unrecoverable and a :exc:`RuntimeError` is raised to signal that |
| 346 | the Celery application must be restarted. |
| 347 | """ |
| 348 | try: |
| 349 | yield |
| 350 | except self._connection_errors: |
| 351 | try: |
| 352 | self._reconnect() |
| 353 | except self._connection_errors as exc: |
| 354 | logger.critical(E_RETRY_LIMIT_EXCEEDED) |
| 355 | raise RuntimeError(E_RETRY_LIMIT_EXCEEDED) from exc |
| 356 | |
| 357 | def _reconnect(self): |
| 358 | """Re-establish the backend connection. |