Update 'apns2/client.py'

- fix backward compatibility
This commit is contained in:
2022-04-17 10:29:38 +03:00
parent 04bbafd195
commit 34fd0d0264
+17 -15
View File
@@ -89,8 +89,9 @@ class APNsClient(object):
def send_notification(self, token_hex: str, notification: Payload, topic: Optional[str] = None,
priority: NotificationPriority = NotificationPriority.Immediate,
expiration: Optional[int] = None, collapse_id: Optional[str] = None) -> None:
stream_id = self.send_notification_async(token_hex, notification, topic, priority, expiration, collapse_id)
result = self.get_notification_result(stream_id)
stream_id, reason = self.send_notification_async(token_hex, notification, topic, priority, expiration, collapse_id)
result = self.get_notification_result(stream_id, reason)
print(123, result)
if result != 'Success':
if isinstance(result, tuple):
reason, info = result
@@ -242,16 +243,17 @@ class APNsClient(object):
connection fails, the function retries up to MAX_CONNECTION_RETRIES times.
"""
retries = 0
while retries < MAX_CONNECTION_RETRIES:
# noinspection PyBroadException
try:
self._connection.connect()
logger.info('Connected to APNs')
return
except Exception: # pylint: disable=broad-except
# close the connnection, otherwise next connect() call would do nothing
self._connection.close()
retries += 1
logger.exception('Failed connecting to APNs (attempt %s of %s)', retries, MAX_CONNECTION_RETRIES)
raise ConnectionFailed()
return
# while retries < MAX_CONNECTION_RETRIES:
# # noinspection PyBroadException
# try:
# self._connection.connect()
# logger.info('Connected to APNs')
# return
# except Exception: # pylint: disable=broad-except
# # close the connnection, otherwise next connect() call would do nothing
# self._connection.close()
# retries += 1
# logger.exception('Failed connecting to APNs (attempt %s of %s)', retries, MAX_CONNECTION_RETRIES)
#
# raise ConnectionFailed()