Skip to content

Commit

Permalink
Implement retry-logic on protocol errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelengstrom committed Oct 31, 2024

Unverified

The email in this signature doesn’t match the committer email.
1 parent 428cc67 commit ad9bd17
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions push_notifications/apns_async.py
Original file line number Diff line number Diff line change
@@ -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,

0 comments on commit ad9bd17

Please sign in to comment.