Skip to content

Commit c47d97a

Browse files
committed
[#2952] Wrap the zaak notification handler in a Celery task
1 parent ce11922 commit c47d97a

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

src/open_inwoner/openzaak/api/views.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import dataclasses
12
import logging
23

34
from rest_framework import status
@@ -10,7 +11,7 @@
1011
from open_inwoner.openzaak.api_models import Notification
1112
from open_inwoner.openzaak.auth import get_valid_subscription_from_request
1213
from open_inwoner.openzaak.exceptions import InvalidAuth
13-
from open_inwoner.openzaak.notifications import handle_zaken_notification
14+
from open_inwoner.openzaak.tasks import process_zaken_notification
1415
from open_inwoner.utils.logentry import system_action as log_system_action
1516

1617
logger = logging.getLogger(__name__)
@@ -95,4 +96,6 @@ def handle_notification(self, notification: Notification):
9596
config = SiteConfiguration.get_solo()
9697
if not config.notifications_cases_enabled:
9798
return
98-
handle_zaken_notification(notification)
99+
100+
notification_data = dataclasses.asdict(notification)
101+
process_zaken_notification.delay(notification_data)

src/open_inwoner/openzaak/models.py

-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ def form_service(self, service):
424424
),
425425
default=False,
426426
)
427-
428427
order_statuses_by_date_set = models.BooleanField(
429428
verbose_name=_(
430429
"On the detail page of the case, order the statuses based on the date they have been set"

src/open_inwoner/openzaak/tasks.py

+11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
from django.core.management import call_command
55

6+
from zgw_consumers.api_models.base import factory
7+
68
from open_inwoner.celery import app
9+
from open_inwoner.openzaak.api_models import Notification
10+
from open_inwoner.openzaak.notifications import handle_zaken_notification
711

812
logger = logging.getLogger(__name__)
913

@@ -19,3 +23,10 @@ def import_zgw_data():
1923
logger.info("finished import_zgw_data() task")
2024

2125
return out.getvalue()
26+
27+
28+
@app.task
29+
def process_zaken_notification(notification_data: dict):
30+
logger.info("Started process_zaken_notification() task")
31+
notification = factory(Notification, notification_data)
32+
handle_zaken_notification(notification)

src/open_inwoner/openzaak/tests/test_notification_webhook.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from unittest.mock import patch
33

4-
from django.test import TestCase
4+
from django.test import TestCase, override_settings
55
from django.urls import reverse_lazy
66

77
from rest_framework import status
@@ -38,6 +38,7 @@ def generate_auth_header_value(client_id, secret):
3838
return auth_value
3939

4040

41+
@override_settings(CELERY_TASK_ALWAYS_EAGER=True, CELERY_TASK_EAGER_PROPAGATES=True)
4142
class NotificationSubscriptionAuthTest(TestCase):
4243
def test_valid_auth_retrieves_subscription(self):
4344
subscription = SubscriptionFactory(client_id="foo", secret="password")
@@ -76,7 +77,8 @@ def test_invalid_auth_header_raises_exception(self):
7677
get_valid_subscriptions_from_bearer(auth_value)
7778

7879

79-
@patch("open_inwoner.openzaak.api.views.handle_zaken_notification", autospec=True)
80+
@override_settings(CELERY_TASK_ALWAYS_EAGER=True, CELERY_TASK_EAGER_PROPAGATES=True)
81+
@patch("open_inwoner.openzaak.tasks.handle_zaken_notification", autospec=True)
8082
class NotificationWebhookAPITestCase(AssertTimelineLogMixin, APITestCase):
8183
"""
8284
NOTE these tests run against the mounted zaken webhook (eg: ZakenNotificationsWebhookView),

src/open_inwoner/openzaak/tests/test_notification_zaak_status.py

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from .test_notification_data import MockAPIData, MockAPIDataAlt
3030

3131

32+
@override_settings(CELERY_TASK_ALWAYS_EAGER=True, CELERY_TASK_EAGER_PROPAGATES=True)
3233
@requests_mock.Mocker()
3334
@patch("open_inwoner.openzaak.notifications._handle_status_update", autospec=True)
3435
class StatusNotificationHandlerTestCase(

0 commit comments

Comments
 (0)