diff --git a/src/open_inwoner/conf/base.py b/src/open_inwoner/conf/base.py index ea387f6611..9bbf3ae0ae 100644 --- a/src/open_inwoner/conf/base.py +++ b/src/open_inwoner/conf/base.py @@ -692,6 +692,10 @@ "task": "open_inwoner.search.tasks.rebuild_search_index", "schedule": crontab(minute="0", hour="4", day_of_month="*"), }, + "Dagelijkse misluke email samenvatting": { + "task": "open_inwoner.configurations.tasks.send_failed_email_digest", + "schedule": crontab(minute="0", hour="7", day_of_month="*"), + }, "Probeer emails opnieuw te sturen": { "task": "django_yubin.tasks.retry_emails", "schedule": crontab(minute="1", hour="*", day_of_month="*"), diff --git a/src/open_inwoner/configurations/tasks.py b/src/open_inwoner/configurations/tasks.py new file mode 100644 index 0000000000..595f1a232d --- /dev/null +++ b/src/open_inwoner/configurations/tasks.py @@ -0,0 +1,16 @@ +import logging + +from django.core.management import call_command + +from open_inwoner.celery import app + +logger = logging.getLogger(__name__) + + +@app.task +def send_failed_email_digest(): + logger.info("starting send_failed_email_digest() task") + + call_command("send_failed_email_digest") + + logger.info("finished send_failed_email_digest() task") diff --git a/src/open_inwoner/configurations/tests/test_emails.py b/src/open_inwoner/configurations/tests/test_emails.py index c1f983b86e..c4589b8bb2 100644 --- a/src/open_inwoner/configurations/tests/test_emails.py +++ b/src/open_inwoner/configurations/tests/test_emails.py @@ -1,11 +1,15 @@ +from unittest import mock + from django.core import mail from django.core.management import call_command -from django.test import TestCase +from django.test import TestCase, override_settings from django_yubin import send_mail as yubin_send_mail from django_yubin.models import Log from freezegun import freeze_time +from open_inwoner.configurations.tasks import send_failed_email_digest + from ..models import SiteConfiguration @@ -86,3 +90,13 @@ def test_send_daily_failing_email_digest(self): self.assertIn("Should show up in email", email.body) self.assertIn("to@example.com", email.body) self.assertIn("1 januari 2024 13:00", email.body) + + +@override_settings(CELERY_TASK_ALWAYS_EAGER=True) +# Due to Celery's eager task discovery, we have to mock the imported +# call_command. +@mock.patch("open_inwoner.configurations.tasks.call_command") +class DailyFailingEmailDigestTaskTestCase(TestCase): + def test_task_invokes_management_command(self, m): + send_failed_email_digest.delay() + m.assert_called_once_with("send_failed_email_digest")