Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
register_device_to_bouncer: Fix runtime error when retry limit exceeds.
Prakhar Pratyushdf642dc05421
diff --git a/zerver/tests/test_queue_worker.py b/zerver/tests/test_queue_worker.pyindex 40b9a9f319d..6579af5b527 100644--- a/zerver/tests/test_queue_worker.py+++ b/zerver/tests/test_queue_worker.py@@ -555,14 +555,20 @@ class WorkerTest(ZulipTestCase):"zerver.worker.missedmessage_mobile_notifications.handle_remove_push_notification",side_effect=PushNotificationBouncerRetryLaterError("test"),) as mock_handle_remove,+ patch(+ "zerver.worker.missedmessage_mobile_notifications.handle_register_push_device_to_bouncer",+ side_effect=PushNotificationBouncerRetryLaterError("test"),+ ) as mock_handle_register,patch("zerver.worker.missedmessage_mobile_notifications.initialize_push_notifications"),):event_new = generate_new_message_notification()event_remove = generate_remove_notification()+ event_register = generate_register_push_device_to_bouncer()fake_client.enqueue("missedmessage_mobile_notifications", event_new)fake_client.enqueue("missedmessage_mobile_notifications", event_remove)+ fake_client.enqueue("missedmessage_mobile_notifications", event_register)with (mock_queue_publish(@@ -576,13 +582,18 @@ class WorkerTest(ZulipTestCase):worker.start()self.assertEqual(mock_handle_new.call_count, 1 + MAX_REQUEST_RETRIES)self.assertEqual(mock_handle_remove.call_count, 1 + MAX_REQUEST_RETRIES)+ self.assertEqual(mock_handle_register.call_count, 1 + MAX_REQUEST_RETRIES)self.assertEqual(- warn_logs.output,+ warn_logs.output[0:2],["WARNING:zerver.worker.missedmessage_mobile_notifications:Maximum retries exceeded for trigger:1 event:push_notification",]* 2,)+ self.assertEqual(+ warn_logs.output[2],+ "WARNING:zerver.worker.missedmessage_mobile_notifications:Maximum retries exceeded for trigger:(user_id=2, push_account_id=3) event:register_push_device_to_bouncer",+ )@patch("zerver.worker.email_mirror.mirror_email")def test_mirror_worker(self, mock_mirror_email: MagicMock) -> None:diff --git a/zerver/worker/missedmessage_mobile_notifications.py b/zerver/worker/missedmessage_mobile_notifications.pyindex 5792e700d66..a8950f6c138 100644--- a/zerver/worker/missedmessage_mobile_notifications.py+++ b/zerver/worker/missedmessage_mobile_notifications.py@@ -58,9 +58,16 @@ class PushNotificationsWorker(QueueProcessingWorker):except PushNotificationBouncerRetryLaterError:def failure_processor(event: dict[str, Any]) -> None:- logger.warning(- "Maximum retries exceeded for trigger:%s event:push_notification",- event["user_profile_id"],- )+ if event_type == "register_push_device_to_bouncer":+ logger.warning(+ "Maximum retries exceeded for trigger:(user_id=%s, push_account_id=%s) event:register_push_device_to_bouncer",+ event["payload"]["user_profile_id"],+ event["payload"]["push_account_id"],+ )+ else:+ logger.warning(+ "Maximum retries exceeded for trigger:%s event:push_notification",+ event["user_profile_id"],+ )retry_event(self.queue_name, event, failure_processor)