AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(backend): Add retry mechanism for pika publish_message (#9839)
Zamil Majdy055a231aed54
diff --git a/autogpt_platform/backend/backend/data/rabbitmq.py b/autogpt_platform/backend/backend/data/rabbitmq.pyindex 6d56aca61a..e1013cb00f 100644--- a/autogpt_platform/backend/backend/data/rabbitmq.py+++ b/autogpt_platform/backend/backend/data/rabbitmq.py@@ -4,10 +4,18 @@ from enum import Enumfrom typing import Awaitable, Optionalimport aio_pika+import aio_pika.exceptions as aio_eximport pikaimport pika.adapters.blocking_connection+from pika.exceptions import AMQPErrorfrom pika.spec import BasicPropertiesfrom pydantic import BaseModel+from tenacity import (+ retry,+ retry_if_exception_type,+ stop_after_attempt,+ wait_random_exponential,+)from backend.util.retry import conn_retryfrom backend.util.settings import Settings@@ -161,6 +169,12 @@ class SyncRabbitMQ(RabbitMQBase):routing_key=queue.routing_key or queue.name,)+ @retry(+ retry=retry_if_exception_type((AMQPError, ConnectionError)),+ wait=wait_random_exponential(multiplier=1, max=5),+ stop=stop_after_attempt(5),+ reraise=True,+ )def publish_message(self,routing_key: str,@@ -258,6 +272,12 @@ class AsyncRabbitMQ(RabbitMQBase):exchange, routing_key=queue.routing_key or queue.name)+ @retry(+ retry=retry_if_exception_type((aio_ex.AMQPError, ConnectionError)),+ wait=wait_random_exponential(multiplier=1, max=5),+ stop=stop_after_attempt(5),+ reraise=True,+ )async def publish_message(self,routing_key: str,