From 65bceaa297fcb54cae80d0f2b2d5c280596bd3f2 Mon Sep 17 00:00:00 2001 From: Joey Orlando Date: Tue, 29 Aug 2023 16:02:09 +0200 Subject: [PATCH] rename notify_user_async celery task to notify_user_about_new_alert_group (#2900) # What this PR does Follow up to #2888, rename `notify_user_async` celery task to `notify_user_about_new_alert_group`. ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --- engine/apps/mobile_app/backend.py | 4 ++-- engine/apps/mobile_app/tasks/__init__.py | 2 +- engine/apps/mobile_app/tasks/new_alert_group.py | 8 +++++++- .../mobile_app/tests/tasks/test_new_alert_group.py | 10 +++++----- engine/settings/prod_without_db.py | 2 ++ 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/engine/apps/mobile_app/backend.py b/engine/apps/mobile_app/backend.py index 3e1598f7..463af8b4 100644 --- a/engine/apps/mobile_app/backend.py +++ b/engine/apps/mobile_app/backend.py @@ -3,7 +3,7 @@ import json from django.conf import settings from apps.base.messaging import BaseMessagingBackend -from apps.mobile_app.tasks.new_alert_group import notify_user_async +from apps.mobile_app.tasks.new_alert_group import notify_user_about_new_alert_group class MobileAppBackend(BaseMessagingBackend): @@ -44,7 +44,7 @@ class MobileAppBackend(BaseMessagingBackend): return {"connected": MobileAppAuthToken.objects.filter(user=user).exists()} def notify_user(self, user, alert_group, notification_policy, critical=False): - notify_user_async.delay( + notify_user_about_new_alert_group.delay( user_pk=user.pk, alert_group_pk=alert_group.pk, notification_policy_pk=notification_policy.pk, diff --git a/engine/apps/mobile_app/tasks/__init__.py b/engine/apps/mobile_app/tasks/__init__.py index 445f4f4c..42e04767 100644 --- a/engine/apps/mobile_app/tasks/__init__.py +++ b/engine/apps/mobile_app/tasks/__init__.py @@ -2,7 +2,7 @@ from .going_oncall_notification import ( # noqa:F401 conditionally_send_going_oncall_push_notifications_for_all_schedules, conditionally_send_going_oncall_push_notifications_for_schedule, ) -from .new_alert_group import notify_user_async # noqa:F401 +from .new_alert_group import notify_user_about_new_alert_group, notify_user_async # noqa:F401 from .new_shift_swap_request import ( # noqa:F401 notify_shift_swap_request, notify_shift_swap_requests, diff --git a/engine/apps/mobile_app/tasks/new_alert_group.py b/engine/apps/mobile_app/tasks/new_alert_group.py index f7c6d739..eb211127 100644 --- a/engine/apps/mobile_app/tasks/new_alert_group.py +++ b/engine/apps/mobile_app/tasks/new_alert_group.py @@ -90,7 +90,7 @@ def _get_fcm_message(alert_group: AlertGroup, user: User, device_to_notify: "FCM @shared_dedicated_queue_retry_task(autoretry_for=(Exception,), retry_backoff=True, max_retries=MAX_RETRIES) -def notify_user_async(user_pk, alert_group_pk, notification_policy_pk, critical): +def notify_user_about_new_alert_group(user_pk, alert_group_pk, notification_policy_pk, critical): # avoid circular import from apps.base.models import UserNotificationPolicy, UserNotificationPolicyLogRecord from apps.mobile_app.models import FCMDevice @@ -137,3 +137,9 @@ def notify_user_async(user_pk, alert_group_pk, notification_policy_pk, critical) message = _get_fcm_message(alert_group, user, device_to_notify, critical) send_push_notification(device_to_notify, message, _create_error_log_record) + + +# TODO: remove this in a future release +@shared_dedicated_queue_retry_task(autoretry_for=(Exception,), retry_backoff=True, max_retries=MAX_RETRIES) +def notify_user_async(user_pk, alert_group_pk, notification_policy_pk, critical): + notify_user_about_new_alert_group(user_pk, alert_group_pk, notification_policy_pk, critical) diff --git a/engine/apps/mobile_app/tests/tasks/test_new_alert_group.py b/engine/apps/mobile_app/tests/tasks/test_new_alert_group.py index a7f97adb..5c784497 100644 --- a/engine/apps/mobile_app/tests/tasks/test_new_alert_group.py +++ b/engine/apps/mobile_app/tests/tasks/test_new_alert_group.py @@ -4,7 +4,7 @@ import pytest from apps.base.models import UserNotificationPolicy, UserNotificationPolicyLogRecord from apps.mobile_app.models import FCMDevice, MobileAppUserSettings -from apps.mobile_app.tasks.new_alert_group import _get_fcm_message, notify_user_async +from apps.mobile_app.tasks.new_alert_group import _get_fcm_message, notify_user_about_new_alert_group MOBILE_APP_BACKEND_ID = 5 CLOUD_LICENSE_NAME = "Cloud" @@ -13,7 +13,7 @@ OPEN_SOURCE_LICENSE_NAME = "OpenSource" @patch("apps.mobile_app.tasks.new_alert_group.send_push_notification") @pytest.mark.django_db -def test_notify_user_async( +def test_notify_user_about_new_alert_group( mock_send_push_notification, make_organization_and_user, make_user_notification_policy, @@ -37,7 +37,7 @@ def test_notify_user_async( alert_group = make_alert_group(alert_receive_channel, channel_filter=channel_filter) make_alert(alert_group=alert_group, raw_request_data={}) - notify_user_async( + notify_user_about_new_alert_group( user_pk=user.pk, alert_group_pk=alert_group.pk, notification_policy_pk=notification_policy.pk, @@ -49,7 +49,7 @@ def test_notify_user_async( @patch("apps.mobile_app.tasks.new_alert_group.send_push_notification") @pytest.mark.django_db -def test_notify_user_async_no_device_connected( +def test_notify_user_about_new_alert_group_no_device_connected( mock_send_push_notification, make_organization_and_user, make_user_notification_policy, @@ -72,7 +72,7 @@ def test_notify_user_async_no_device_connected( alert_group = make_alert_group(alert_receive_channel, channel_filter=channel_filter) make_alert(alert_group=alert_group, raw_request_data={}) - notify_user_async( + notify_user_about_new_alert_group( user_pk=user.pk, alert_group_pk=alert_group.pk, notification_policy_pk=notification_policy.pk, diff --git a/engine/settings/prod_without_db.py b/engine/settings/prod_without_db.py index b4c4428f..c5bab5d2 100644 --- a/engine/settings/prod_without_db.py +++ b/engine/settings/prod_without_db.py @@ -112,7 +112,9 @@ CELERY_TASK_ROUTES = { "apps.integrations.tasks.create_alert": {"queue": "critical"}, "apps.integrations.tasks.create_alertmanager_alerts": {"queue": "critical"}, "apps.integrations.tasks.start_notify_about_integration_ratelimit": {"queue": "critical"}, + # TODO: remove apps.mobile_app.tasks.notify_user_async in a future release "apps.mobile_app.tasks.notify_user_async": {"queue": "critical"}, + "apps.mobile_app.tasks.notify_user_about_new_alert_group": {"queue": "critical"}, "apps.schedules.tasks.drop_cached_ical.drop_cached_ical_for_custom_events_for_organization": {"queue": "critical"}, "apps.schedules.tasks.drop_cached_ical.drop_cached_ical_task": {"queue": "critical"}, # LONG