Skip to content

Commit

Permalink
[#2657] migrate send_failed_email_digest cron to Celery
Browse files Browse the repository at this point in the history
  • Loading branch information
swrichards committed Aug 7, 2024
1 parent 5ad2a76 commit 84b589f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="*"),
Expand Down
16 changes: 16 additions & 0 deletions src/open_inwoner/configurations/tasks.py
Original file line number Diff line number Diff line change
@@ -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")
16 changes: 15 additions & 1 deletion src/open_inwoner/configurations/tests/test_emails.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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")

0 comments on commit 84b589f

Please sign in to comment.