Repository: celery/celery
File: celery/worker/consumer/delayed_delivery.py (Python)

Code before:
                    queue.name, str(e)
                )

                # We must re-raise on retried exceptions to ensure they are
                # caught with the outer retry_over_time mechanism.
                #
                # This could be removed if:
                # * The minimum python version for Celery and Kombu is increased
                #   to 3.11.
                # * Kombu updated to use the `except*` clause to catch specific
                #   exceptions from an ExceptionGroup.
                # * We switch to using ExceptionGroup below to raise multiple
                #   exceptions.
                if isinstance(e, RETRIED_EXCEPTIONS):
                    raise

                exceptions.append(e)

        if exceptions:
            # Raise a single exception summarizing all binding failures
            # In Python 3.11+, we could use ExceptionGroup here instead.
            raise RuntimeError(
                ("One or more failures occurred while binding queues to "
                 "delayed delivery exchanges\n") +
                "\n".join(str(e) for e in exceptions),
            )

    def _on_retry(self, exc: Exception, interval_range: Iterator[float], intervals_count: int) -> float:
        """Callback for retry attempts.

        Args:
            exc: The exception that triggered the retry
            interval_range: An iterator which returns the time in seconds to sleep next
            intervals_count: Number of retry attempts so far
        """
        interval = next(interval_range)
        logger.warning(
            "Retrying delayed delivery setup (attempt %d/%d) after error: %s. Sleeping %.2f seconds.",
            intervals_count + 1, MAX_RETRIES, str(exc), interval
        )
        return interval

    def _validate_configuration(self, app: Celery) -> None:
        """Validate all required configuration settings.

        Args:
            app: The Celery application instance

        Raises:
            ValueError: If any configuration is invalid
        """

Review comment (suggestion):
Alternatively, this backport of [PEP 654's ExceptionGroup](https://github.com/agronholm/exceptiongroup) could be used when the runtime python version of < 3.11.  I've not used this backport before and can't endorse it.

Code after:
            except Exception as e:
                logger.error(
                    "Failed to bind queue %r: %s",
                    queue.name, str(e)
                )

                # We must re-raise on retried exceptions to ensure they are
                # caught with the outer retry_over_time mechanism.
                #
                # This could be removed if one of:
                # * The minimum python version for Celery and Kombu is
                #   increased to 3.11. Kombu updated to use the `except*`
                #   clause to catch specific exceptions from an ExceptionGroup.
                # * Kombu's retry_over_time utility is updated to use the
                #   catch utility from agronholm's exceptiongroup backport.
                if isinstance(e, RETRIED_EXCEPTIONS):
                    raise

                exceptions.append(e)

        if exceptions:
            raise ExceptionGroup(
                ("One or more failures occurred while binding queues to "
                 "delayed delivery exchanges"),
                exceptions,
            )

    def _on_retry(self, exc: Exception, interval_range: Iterator[float], intervals_count: int) -> float:
        """Callback for retry attempts.

        Args:
            exc: The exception that triggered the retry
            interval_range: An iterator which returns the time in seconds to sleep next
            intervals_count: Number of retry attempts so far
        """
        interval = next(interval_range)
        logger.warning(
            "Retrying delayed delivery setup (attempt %d/%d) after error: %s. Sleeping %.2f seconds.",
            intervals_count + 1, MAX_RETRIES, str(exc), interval
        )
        return interval

    def _validate_configuration(self, app: Celery) -> None:
        """Validate all required configuration settings.

        Args:
            app: The Celery application instance

        Raises:
            ValueError: If any configuration is invalid
        """