From 5f4ea6e93279886c16699763b3e34eee92f8f3ce Mon Sep 17 00:00:00 2001 From: jamshale Date: Thu, 15 Aug 2024 21:44:18 +0000 Subject: [PATCH] Adjust message queue error handling Signed-off-by: jamshale --- .../transport/outbound/manager.py | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/aries_cloudagent/transport/outbound/manager.py b/aries_cloudagent/transport/outbound/manager.py index 55be0bd8d4..0ee1258b74 100644 --- a/aries_cloudagent/transport/outbound/manager.py +++ b/aries_cloudagent/transport/outbound/manager.py @@ -470,40 +470,43 @@ def deliver_queued_message(self, queued: QueuedOutboundMessage) -> asyncio.Task: ) return queued.task + def _finished_deliver_error_handler(self, queued: QueuedOutboundMessage, retry: bool): + if retry: + LOGGER.debug( + ( + ">>> Error when posting to: %s; " + "Error: %s; " + "Payload: %s; Re-queue failed message ..." + ), + queued.endpoint, + queued.error, + queued.payload, + ) + else: + err_msg = ">>> Outbound message failed to deliver, NOT Re-queued." + if "/webhook/topic" in queued.endpoint: + LOGGER.warning( + err_msg, + exc_info=queued.error, + ) + else: + LOGGER.exception( + err_msg, + exc_info=queued.error, + ) + def finished_deliver(self, queued: QueuedOutboundMessage, completed: CompletedTask): """Handle completion of queued message delivery.""" if completed.exc_info: queued.error = completed.exc_info if queued.retries: - if LOGGER.isEnabledFor(logging.DEBUG): - LOGGER.error( - ( - ">>> Error when posting to: %s; " - "Error: %s; " - "Payload: %s; Re-queue failed message ..." - ), - queued.endpoint, - queued.error, - queued.payload, - ) - else: - LOGGER.error( - ( - ">>> Error when posting to: %s; " - "Error: %s; Re-queue failed message ..." - ), - queued.endpoint, - queued.error, - ) + self._finished_deliver_error_handler(queued, retry=True) queued.retries -= 1 queued.state = QueuedOutboundMessage.STATE_RETRY queued.retry_at = time.perf_counter() + 10 else: - LOGGER.exception( - ">>> Outbound message failed to deliver, NOT Re-queued.", - exc_info=queued.error, - ) + self._finished_deliver_error_handler(queued, retry=False) queued.state = QueuedOutboundMessage.STATE_DONE else: queued.error = None