Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore events after action is completed #619

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions eventstore/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,10 @@ def update_whatsapp_template_send_status(message_id, preferred_channel=None):
status = WhatsAppTemplateSendStatus.objects.get(
message_id=message_id, event_received_at__isnull=True
)

if status.status == WhatsAppTemplateSendStatus.Status.ACTION_COMPLETED:
return

status.event_received_at = timezone.now()
status.status = WhatsAppTemplateSendStatus.Status.EVENT_RECEIVED

Expand Down
18 changes: 18 additions & 0 deletions eventstore/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,24 @@ def test_update_status_sms(self, mock_flow_start):
self.assertIsNotNone(self.status.event_received_at)
mock_flow_start.assert_not_called()

@mock.patch("eventstore.tasks.async_create_flow_start")
def test_update_status_action_completed(self, mock_flow_start):
"""
If the status record is already action_completed then do nothing.
"""
self.status.status = WhatsAppTemplateSendStatus.Status.ACTION_COMPLETED
self.status.save()
tasks.update_whatsapp_template_send_status(self.status.message_id, "SMS")

self.status.refresh_from_db()

self.assertEqual(
self.status.status, WhatsAppTemplateSendStatus.Status.ACTION_COMPLETED
)
self.assertEqual(self.status.preferred_channel, "WhatsApp")
self.assertIsNone(self.status.event_received_at)
mock_flow_start.assert_not_called()


class ProcessWhatsAppTemplateSendStatusTests(TestCase):
def setUp(self):
Expand Down
Loading