Merge pull request #1353 from alphagov/add-task-for-ses-results-queue

Retry in only certain scenarios
This commit is contained in:
Richard Chapman
2017-10-30 14:02:44 +00:00
committed by GitHub
2 changed files with 14 additions and 3 deletions

View File

@@ -555,7 +555,10 @@ def process_incomplete_job(job_id):
@notify_celery.task(bind=True, name="process-ses-result", max_retries=5, default_retry_delay=300)
@statsd(namespace="tasks")
def process_ses_results(self, response):
errors = process_ses_response(response)
if errors:
current_app.logger.error(errors)
try:
errors = process_ses_response(response)
if errors:
current_app.logger.error(errors)
except Exception:
current_app.logger.exception('Error processing SES results')
self.retry(queue=QueueNames.RETRY, exc="SES responses processed with error")

View File

@@ -1398,7 +1398,15 @@ def test_process_ses_results(notify_db, notify_db_session, sample_email_template
assert process_ses_results(response=response) is None
def test_process_ses_results_does_not_retry_if_errors(notify_db, mocker):
mocked = mocker.patch('app.celery.tasks.process_ses_results.retry')
response = json.loads(ses_notification_callback())
process_ses_results(response=response)
assert mocked.call_count == 0
def test_process_ses_results_retry_called(notify_db, mocker):
mocker.patch("app.dao.notifications_dao.update_notification_status_by_reference", side_effect=Exception("EXPECTED"))
mocked = mocker.patch('app.celery.tasks.process_ses_results.retry')
response = json.loads(ses_notification_callback())
process_ses_results(response=response)