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 3 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 @@ def bulk_send(self, events):
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 ids:
logger.info(f"Found duplicated event {updated_event['id']}")
continue
prepared_events.append(updated_event)
ids.add(updated_event["id"])

if prepared_events: # pragma: no cover
self.dispatch_bulk_events(
Expand Down
15 changes: 15 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,16 @@ def setUp(self):
},
},
{
'id': 'some-uuid-3',
'name': str(sentinel.name),
'transformed': True,
'event_time': '2020-01-01T12:12:12.000000+00:02',
'data': {
'key': 'value 2'
},
},
{
'id': 'some-uuid-3',
'name': str(sentinel.name),
'transformed': True,
'event_time': '2020-01-01T12:12:12.000000+00:02',
Expand Down Expand Up @@ -841,6 +854,7 @@ def test_successful_routing_of_bulk_events(
router.bulk_send(self.bulk_transformed_events)

overridden_events = self.bulk_transformed_events.copy()
overridden_events.pop()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you comment why you're doing this? I'm sure I will forget as soon as this is merged. :)


for event in overridden_events:
event['new_key'] = 'new_value'
Expand Down Expand Up @@ -1145,6 +1159,7 @@ def test_successful_routing_of_bulk_events(
router.bulk_send(self.bulk_transformed_events)

overridden_events = self.bulk_transformed_events.copy()
overridden_events.pop()

for event in overridden_events:
event['new_key'] = 'new_value'
Expand Down