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

fix: do not send duplicated events in batch #462

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions event_routing_backends/backends/events_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,13 @@
for events_for_route in event_routes.values():
prepared_events = []
host = None
ids = set()
for _, updated_event, host, _ in events_for_route:
if updated_event["id"] in set():
logger.info(f"Found duplicated event {updated_event['id']}")
continue

Check warning on line 162 in event_routing_backends/backends/events_router.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/backends/events_router.py#L161-L162

Added lines #L161 - L162 were not covered by tests
prepared_events.append(updated_event)
ids.add(updated_event["id"])

if prepared_events: # pragma: no cover
self.dispatch_bulk_events(
Expand Down
4 changes: 4 additions & 0 deletions event_routing_backends/backends/tests/test_events_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def setUp(self):
}

self.transformed_event = {
'id': 'some-random-uuid',
'name': str(sentinel.name),
'transformed': True,
'event_time': '2020-01-01T12:12:12.000000+00:00',
Expand Down Expand Up @@ -126,6 +127,7 @@ def setUp(self):

self.bulk_transformed_events = [
{
'id': 'some-uuid-1',
'name': str(sentinel.name),
'transformed': True,
'event_time': '2020-01-01T12:12:12.000000+00:00',
Expand All @@ -134,6 +136,7 @@ def setUp(self):
},
},
{
'id': 'some-uuid-2',
'name': str(sentinel.name),
'transformed': True,
'event_time': '2020-01-01T12:12:12.000000+00:01',
Expand All @@ -142,6 +145,7 @@ def setUp(self):
},
},
{
'id': 'some-uuid-3',
'name': str(sentinel.name),
'transformed': True,
'event_time': '2020-01-01T12:12:12.000000+00:02',
Expand Down