Skip to content

Commit

Permalink
Merge pull request #5317 from akvo/send-link-report-in-email
Browse files Browse the repository at this point in the history
Send report error email only when maxxed attempts
  • Loading branch information
zuhdil authored Dec 12, 2023
2 parents da0f578 + a2c2b9b commit ad870d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion akvo/rsr/tests/views/py_reports/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import binascii
from datetime import timedelta
from typing import cast
from django.conf import settings
from django.core import mail
from django.core.files.storage import Storage, default_storage
from django.test import override_settings
Expand Down Expand Up @@ -49,6 +50,7 @@ def test_cleanup_expired_reports_deletes_file(self):
class NotifyErrorTestCase(BaseTestCase):
def setUp(self):
super().setUp()
max_attempts = getattr(settings, 'Q_CLUSTER', {}).get('max_attempts', 1)
self.create_user('[email protected]')
self.failed_task = Task.objects.create(
id=self._generate_id(),
Expand All @@ -57,7 +59,8 @@ def setUp(self):
result='error',
success=False,
started=timezone.now(),
stopped=timezone.now()
stopped=timezone.now(),
attempt_count=max_attempts
)
self.success_task = Task.objects.create(
id=self._generate_id(),
Expand Down
6 changes: 6 additions & 0 deletions akvo/rsr/views/py_reports/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
def notify_user_on_failed_report(task: Task):
if task.success:
return
max_attempts = getattr(settings, 'Q_CLUSTER', {}).get('max_attempts', 1)
if task.attempt_count < max_attempts:
return
payload, recipient = task.args
user = User.objects.get(email=recipient)
report_label = payload.get('report_label', '')
Expand All @@ -61,6 +64,9 @@ def notify_user_on_failed_report(task: Task):
def notify_dev_on_failed_task(task: Task):
if task.success:
return
max_attempts = getattr(settings, 'Q_CLUSTER', {}).get('max_attempts', 1)
if task.attempt_count < max_attempts:
return
recipient = getattr(settings, 'REPORT_ERROR_RECIPIENTS', [])
if not recipient:
return
Expand Down

0 comments on commit ad870d1

Please sign in to comment.