Skip to content

Commit 35b3b62

Browse files
committed
Remove delay from retry loop
We will schedule retrying failed message batches and manage the delay by schedule.
1 parent 1da75eb commit 35b3b62

File tree

3 files changed

+0
-34
lines changed

3 files changed

+0
-34
lines changed

manage_breast_screening/config/.env.tpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ CIS2_CLIENT_PUBLIC_KEY="paste-pem-public-key-here"
2424
CIS2_DEBUG=False
2525

2626
NOTIFICATIONS_BATCH_RETRY_LIMIT=5
27-
NOTIFICATIONS_BATCH_RETRY_DELAY=10
2827

2928
BASIC_AUTH_ENABLED=False
3029
BASIC_AUTH_USERNAME=changeme

manage_breast_screening/notifications/management/commands/retry_failed_message_batch.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import os
3-
import time
43
from logging import getLogger
54

65
from django.core.management.base import BaseCommand, CommandError
@@ -52,9 +51,6 @@ def handle(self, *args, **options):
5251
logger.info(
5352
f"Retrying Message Batch with id {message_batch_id} with retry count {retry_count}"
5453
)
55-
time.sleep(
56-
int(os.getenv("NOTIFICATIONS_BATCH_RETRY_DELAY", "0")) * retry_count
57-
)
5854

5955
try:
6056
response = ApiClient().send_message_batch(message_batch)

manage_breast_screening/notifications/tests/management/commands/test_retry_failed_message_batch.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ def setup(monkeypatch):
2929
@patch.object(Queue, "RetryMessageBatches", return_value=MagicMock(spec=Queue))
3030
@patch.object(MessageBatchHelpers, "mark_batch_as_sent")
3131
@patch.object(MessageBatchHelpers, "mark_batch_as_failed")
32-
@patch("time.sleep", return_value=MagicMock())
3332
class TestRetryFailedMessageBatch:
3433
@pytest.mark.django_db
3534
def test_handle_batch_not_found(
3635
self,
37-
mock_sleep,
3836
mock_mark_batch_as_failed,
3937
mock_mark_batch_as_sent,
4038
mock_retry_message_batches,
@@ -59,7 +57,6 @@ def test_handle_batch_not_found(
5957
@pytest.mark.django_db
6058
def test_not_failed_yet(
6159
self,
62-
mock_sleep,
6360
mock_mark_batch_as_failed,
6461
mock_mark_batch_as_sent,
6562
mock_retry_message_batches,
@@ -83,7 +80,6 @@ def test_not_failed_yet(
8380
@pytest.mark.django_db
8481
def test_server_error_when_resending_batch(
8582
self,
86-
mock_sleep,
8783
mock_mark_batch_as_failed,
8884
mock_mark_batch_as_sent,
8985
mock_retry_message_batches,
@@ -110,7 +106,6 @@ def test_server_error_when_resending_batch(
110106
@pytest.mark.django_db
111107
def test_successfully_resends_batch(
112108
self,
113-
mock_sleep,
114109
mock_mark_batch_as_failed,
115110
mock_mark_batch_as_sent,
116111
mock_retry_message_batches,
@@ -133,12 +128,10 @@ def test_successfully_resends_batch(
133128
message_batch=failed_batch, response_json=ANY
134129
)
135130
mock_retry_message_batches.return_value.delete.assert_called_with(mocked_item())
136-
mock_sleep.assert_called_with(10)
137131

138132
@pytest.mark.django_db
139133
def test_no_batches_in_queue(
140134
self,
141-
mock_sleep,
142135
mock_mark_batch_as_failed,
143136
mock_mark_batch_as_sent,
144137
mock_retry_message_batches,
@@ -157,7 +150,6 @@ def test_no_batches_in_queue(
157150
@pytest.mark.django_db
158151
def test_batch_with_retry_count_more_than_5_is_marked_as_failed_unrecoverable(
159152
self,
160-
mock_sleep,
161153
mock_mark_batch_as_failed,
162154
mock_mark_batch_as_sent,
163155
mock_retry_message_batches,
@@ -178,24 +170,3 @@ def test_batch_with_retry_count_more_than_5_is_marked_as_failed_unrecoverable(
178170
str(error.value)
179171
== f"Message Batch with id {batch_id} not sent: Retry limit exceeded"
180172
)
181-
182-
@pytest.mark.django_db
183-
def test_sleeps_based_on_retry_count(
184-
self,
185-
mock_sleep,
186-
mock_mark_batch_as_failed,
187-
mock_mark_batch_as_sent,
188-
mock_retry_message_batches,
189-
mock_send_message_batch,
190-
):
191-
mock_send_message_batch.return_value.status_code = 201
192-
subject = Command()
193-
batch_id = uuid.uuid4()
194-
_failed_batch = MessageBatchFactory(id=batch_id, status="failed_recoverable")
195-
mock_retry_message_batches.return_value.item.return_value.content = json.dumps(
196-
{"message_batch_id": str(batch_id), "retry_count": 3}
197-
)
198-
199-
subject.handle()
200-
201-
mock_sleep.assert_called_with(30)

0 commit comments

Comments
 (0)