From a595316e4f0fabd245904544421c5362cd4d500a Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Wed, 8 Feb 2023 12:03:57 +1100 Subject: [PATCH] fix crash recovery --- tools/pushNotificationHandler.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tools/pushNotificationHandler.py b/tools/pushNotificationHandler.py index 5d261fd..4bf2c45 100644 --- a/tools/pushNotificationHandler.py +++ b/tools/pushNotificationHandler.py @@ -179,13 +179,13 @@ class PushNotificationHelperV2(metaclass=Singleton): self.logger.info(f'Ignore message to {recipient}.') try: asyncio.ensure_future(self.execute_push_ios(notifications_ios)) - self.execute_push_android(notifications_android) - self.execute_push_huawei(notifications_huawei) + asyncio.ensure_future(self.execute_push_android(notifications_android)) + asyncio.ensure_future(self.execute_push_huawei(notifications_huawei)) except Exception as e: self.logger.info('Something wrong happened when try to push notifications.') self.logger.exception(e) - def execute_push_android(self, notifications): + async def execute_push_android(self, notifications): if len(notifications) == 0: return self.logger.info(f"Push {len(notifications)} notifications for Android.") @@ -209,7 +209,7 @@ class PushNotificationHelperV2(metaclass=Singleton): else: self.push_fails[token] = 0 - def execute_push_huawei(self, notifications): + async def execute_push_huawei(self, notifications): if len(notifications) == 0: return 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 send_request(notification): - response = await self.apns.send_notification(notification) - if not response.is_successful: - self.handle_fail_result(notification.device_token, (response.description, '')) - else: - self.push_fails[notification.device_token] = 0 + try: + response = await self.apns.send_notification(notification) + if not response.is_successful: + self.handle_fail_result(notification.device_token, (response.description, '')) + else: + self.push_fails[notification.device_token] = 0 + except Exception as e: + self.logger.exception(e) if len(notifications) == 0: return