fix crash recovery

This commit is contained in:
ryanzhao 2023-02-08 12:03:57 +11:00
parent 9761d74406
commit a595316e4f
1 changed files with 12 additions and 9 deletions

View File

@ -179,13 +179,13 @@ class PushNotificationHelperV2(metaclass=Singleton):
self.logger.info(f'Ignore message to {recipient}.') self.logger.info(f'Ignore message to {recipient}.')
try: try:
asyncio.ensure_future(self.execute_push_ios(notifications_ios)) asyncio.ensure_future(self.execute_push_ios(notifications_ios))
self.execute_push_android(notifications_android) asyncio.ensure_future(self.execute_push_android(notifications_android))
self.execute_push_huawei(notifications_huawei) asyncio.ensure_future(self.execute_push_huawei(notifications_huawei))
except Exception as e: except Exception as e:
self.logger.info('Something wrong happened when try to push notifications.') self.logger.info('Something wrong happened when try to push notifications.')
self.logger.exception(e) self.logger.exception(e)
def execute_push_android(self, notifications): async def execute_push_android(self, notifications):
if len(notifications) == 0: if len(notifications) == 0:
return return
self.logger.info(f"Push {len(notifications)} notifications for Android.") self.logger.info(f"Push {len(notifications)} notifications for Android.")
@ -209,7 +209,7 @@ class PushNotificationHelperV2(metaclass=Singleton):
else: else:
self.push_fails[token] = 0 self.push_fails[token] = 0
def execute_push_huawei(self, notifications): async def execute_push_huawei(self, notifications):
if len(notifications) == 0: if len(notifications) == 0:
return return
self.logger.info(f"Push {len(notifications)} notifications for Huawei.") self.logger.info(f"Push {len(notifications)} notifications for Huawei.")
@ -227,11 +227,14 @@ class PushNotificationHelperV2(metaclass=Singleton):
async def execute_push_ios(self, notifications): async def execute_push_ios(self, notifications):
async def send_request(notification): async def send_request(notification):
response = await self.apns.send_notification(notification) try:
if not response.is_successful: response = await self.apns.send_notification(notification)
self.handle_fail_result(notification.device_token, (response.description, '')) if not response.is_successful:
else: self.handle_fail_result(notification.device_token, (response.description, ''))
self.push_fails[notification.device_token] = 0 else:
self.push_fails[notification.device_token] = 0
except Exception as e:
self.logger.exception(e)
if len(notifications) == 0: if len(notifications) == 0:
return return