Skip to content

Commit

Permalink
2172 - use apply async instead of delay
Browse files Browse the repository at this point in the history
  • Loading branch information
MackHalliday committed Feb 3, 2025
1 parent a126db8 commit a89ac4b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/v2/notifications/rest_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def push_notification_helper(schema: dict):

try:
# Choosing to use the email queue for push to limit the number of empty queues
deliver_push.delay(payload)
deliver_push.apply_async(payload)
except (CeleryError, OperationalError):
current_app.logger.exception('Failed to enqueue deliver_push request')
response = jsonify(result='error', message='VA Notify service impaired, please try again'), 502
Expand Down
2 changes: 1 addition & 1 deletion tests/app/integration/test_push_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_mobile_app_push_notification_celery_exception(
service = sample_service(service_permissions=[PUSH_TYPE])
api_key = sample_api_key(service=service)

mocker.patch('app.v2.notifications.rest_push.deliver_push.delay', side_effect=test_exception)
mocker.patch('app.v2.notifications.rest_push.deliver_push.apply_async', side_effect=test_exception)
push_request_body = {
'mobile_app': 'VETEXT',
'template_id': 'some-template-id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_does_not_accept_extra_fields(
class TestPushSending:
@pytest.fixture()
def deliver_push_celery(self, mocker):
mocker.patch('app.v2.notifications.rest_push.deliver_push.delay')
mocker.patch('app.v2.notifications.rest_push.deliver_push.apply_async')

def test_returns_201(self, client, sample_api_key, sample_service, deliver_push_celery):
service = sample_service(service_permissions=[PUSH_TYPE])
Expand All @@ -129,7 +129,7 @@ def test_returns_201_after_read_timeout(

@pytest.mark.parametrize('side_effect', [CeleryError, OperationalError])
def test_celery_returns_502(self, client, sample_api_key, sample_service, mocker, side_effect):
mocker.patch('app.v2.notifications.rest_push.deliver_push.delay', side_effect=side_effect)
mocker.patch('app.v2.notifications.rest_push.deliver_push.apply_async', side_effect=side_effect)
service = sample_service(service_permissions=[PUSH_TYPE])
response = post_send_push_broadcast_notification(client, sample_api_key(service), PUSH_BROADCAST_REQUEST)
assert response.status_code == 502
4 changes: 2 additions & 2 deletions tests/app/v2/notifications/test_push_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_does_not_accept_extra_fields(
class TestDeliverPushCelery:
@pytest.fixture()
def deliver_push_celery(self, mocker):
mocker.patch('app.v2.notifications.rest_push.deliver_push.delay')
mocker.patch('app.v2.notifications.rest_push.deliver_push.apply_async')

def test_returns_201(
self,
Expand Down Expand Up @@ -165,7 +165,7 @@ def test_returns_201_after_read_timeout(

@pytest.mark.parametrize('side_effect', [CeleryError, OperationalError])
def test_celery_returns_502(self, client, sample_api_key, sample_service, mocker, side_effect):
mocker.patch('app.v2.notifications.rest_push.deliver_push.delay', side_effect=side_effect)
mocker.patch('app.v2.notifications.rest_push.deliver_push.apply_async', side_effect=side_effect)
service = sample_service(service_permissions=[PUSH_TYPE])
response = post_send_notification(client, sample_api_key(service), PUSH_TYPE, PUSH_REQUEST)
assert response.status_code == 502

0 comments on commit a89ac4b

Please sign in to comment.