From ad9bd17b7e9b30d10205dbd611ba18540ac462b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20Engstr=C3=B6m?= Date: Thu, 31 Oct 2024 10:26:22 +0100 Subject: [PATCH] Implement retry-logic on protocol errors --- push_notifications/apns_async.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/push_notifications/apns_async.py b/push_notifications/apns_async.py index 1b98cf89..8b6d363f 100644 --- a/push_notifications/apns_async.py +++ b/push_notifications/apns_async.py @@ -5,6 +5,7 @@ from aioapns import APNs, ConnectionError, NotificationRequest from aioapns.common import NotificationResult +from h2.exceptions import ProtocolError from . import models from .conf import get_manager @@ -142,7 +143,7 @@ def send_message( def send_bulk_messages(self, requests): async def _send(): - semaphore = asyncio.Semaphore(5) + semaphore = asyncio.Semaphore(6) results: tuple[Any] = await asyncio.gather(*(self.send_message_async(request, semaphore) for request in requests)) return results @@ -154,7 +155,11 @@ async def _send(): async def send_message_async(self, request, semaphore): async with semaphore: - response = await self.client.send_notification(request) + try: + response = await self.client.send_notification(request) + except ProtocolError: + await asyncio.sleep(.1) + response = await self.client.send_notification(request) return request.device_token, response,