Skip to content

Commit 3dbedbb

Browse files
committed
feat: message group id for callback entry points (SES, inbound SMS)
1 parent 271aeae commit 3dbedbb

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

app/notifications/notifications_ses_callback.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ def check_and_queue_callback_task(notification):
7474
if service_callback_api:
7575
notification_data = create_delivery_status_callback_data(notification, service_callback_api)
7676
send_delivery_status_to_service.apply_async(
77-
[str(notification.id), notification_data], queue=QueueNames.CALLBACKS
77+
[str(notification.id), notification_data],
78+
queue=QueueNames.CALLBACKS,
79+
MessageGroupId=str(notification.service_id),
7880
)
7981

8082

@@ -83,4 +85,8 @@ def _check_and_queue_complaint_callback_task(complaint, notification, recipient)
8385
service_callback_api = get_complaint_callback_api_for_service(service_id=notification.service_id)
8486
if service_callback_api:
8587
complaint_data = create_complaint_callback_data(complaint, notification, service_callback_api, recipient)
86-
send_complaint_to_service.apply_async([complaint_data], queue=QueueNames.CALLBACKS)
88+
send_complaint_to_service.apply_async(
89+
[complaint_data],
90+
queue=QueueNames.CALLBACKS,
91+
MessageGroupId=str(notification.service_id),
92+
)

app/notifications/receive_notifications.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ def receive_mmg_sms():
6969
)
7070

7171
service_callback_tasks.send_inbound_sms_to_service.apply_async(
72-
[str(inbound.id), str(service.id)], queue=QueueNames.CALLBACKS
72+
[str(inbound.id), str(service.id)],
73+
queue=QueueNames.CALLBACKS,
74+
MessageGroupId=str(service.id),
7375
)
7476

7577
current_app.logger.info(
@@ -115,7 +117,9 @@ def receive_firetext_sms():
115117
INBOUND_SMS_COUNTER.labels("firetext").inc()
116118

117119
service_callback_tasks.send_inbound_sms_to_service.apply_async(
118-
[str(inbound.id), str(service.id)], queue=QueueNames.CALLBACKS
120+
[str(inbound.id), str(service.id)],
121+
queue=QueueNames.CALLBACKS,
122+
MessageGroupId=str(service.id),
119123
)
120124
current_app.logger.info(
121125
"%s received inbound SMS with reference %s from Firetext",

tests/app/notifications/test_notifications_ses_callback.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ def test_check_and_queue_callback_task(mocker, mock_celery_task, sample_notifica
9191
assert mock_create_args[1].id == callback_api.id
9292

9393
mock_send.assert_called_once_with(
94-
[str(sample_notification.id), mock_create.return_value], queue="service-callbacks"
94+
[str(sample_notification.id), mock_create.return_value],
95+
queue="service-callbacks",
96+
MessageGroupId=str(sample_notification.service_id),
9597
)
9698

9799

tests/app/notifications/test_receive_notification.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ def test_receive_notification_returns_received_to_mmg(client, mocker, sample_ser
7272

7373
inbound_sms_id = InboundSms.query.all()[0].id
7474
mocked.assert_called_once_with(
75-
[str(inbound_sms_id), str(sample_service_full_permissions.id)], queue="service-callbacks"
75+
[str(inbound_sms_id), str(sample_service_full_permissions.id)],
76+
queue="service-callbacks",
77+
MessageGroupId=str(sample_service_full_permissions.id),
7678
)
7779

7880

@@ -340,7 +342,11 @@ def test_receive_notification_returns_received_to_firetext(notify_db_session, cl
340342

341343
assert result["status"] == "ok"
342344
inbound_sms_id = InboundSms.query.all()[0].id
343-
mocked.assert_called_once_with([str(inbound_sms_id), str(service.id)], queue="service-callbacks")
345+
mocked.assert_called_once_with(
346+
[str(inbound_sms_id), str(service.id)],
347+
queue="service-callbacks",
348+
MessageGroupId=str(service.id),
349+
)
344350

345351

346352
def test_receive_notification_from_firetext_persists_message(notify_db_session, client, mocker):
@@ -368,7 +374,11 @@ def test_receive_notification_from_firetext_persists_message(notify_db_session,
368374
assert persisted.content == "this is a message"
369375
assert persisted.provider == "firetext"
370376
assert persisted.provider_date == datetime(2017, 1, 1, 12, 0, 0, 0)
371-
mocked.assert_called_once_with([str(persisted.id), str(service.id)], queue="service-callbacks")
377+
mocked.assert_called_once_with(
378+
[str(persisted.id), str(service.id)],
379+
queue="service-callbacks",
380+
MessageGroupId=str(service.id),
381+
)
372382

373383

374384
def test_receive_notification_from_firetext_persists_message_with_normalized_phone(notify_db_session, client, mocker):

0 commit comments

Comments
 (0)