-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat!: new event bus config format #272
Merged
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
726f5eb
feat!: new event bus config format
688a72f
fixup!: ADR
28f5662
fixup!: ADR
ad615f0
fixup!: ADR
d62ca05
fixup!: docs
bc0097c
fixup!: quality
90f8440
fixup!: merge configs
4340f98
fixup!: merge configs
4c9578e
fixup!: versioning
5d7e609
Merge branch 'main' into rsgraber/20230926-update-publish-via-config
815bdf5
fixup!: renumber
c805931
fixup!: docstring
f01b55d
fixup!: fix index
034d4d6
fixup!: quality
e36a22b
fixup!: fix test?
07a8105
Merge branch 'main' into rsgraber/20230926-update-publish-via-config
36ba5dc
Merge branch 'main' into rsgraber/20230926-update-publish-via-config
c82fc3b
fixup!: changes from review
1532ffb
fixup!: space
eb2d9ac
fixup!: space
537ea44
fixup!: comments from review
e25bff8
fixup!: comments from review
4157019
fixup!: comments from review
03e23b8
fixup!: comments from review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,20 +14,20 @@ def general_signal_handler(sender, signal, **kwargs): # pylint: disable=unused- | |||||
""" | ||||||
Signal handler for publishing events to configured event bus. | ||||||
""" | ||||||
event_type_publish_configs = getattr(settings, "EVENT_BUS_PRODUCER_CONFIG", {}).get(signal.event_type, {}) | ||||||
# event_type_publish_configs should look something like | ||||||
event_type_producer_configs = getattr(settings, "EVENT_BUS_PRODUCER_CONFIG", {}).get(signal.event_type, {}) | ||||||
# event_type_producer_configs should look something like | ||||||
# { | ||||||
# "topic_a": { "event_key_field": "my.key.field", "enabled": True }, | ||||||
# "topic_b": { "event_key_field": "my.key.field", "enabled": False } | ||||||
# }" | ||||||
event_data = {key: kwargs.get(key) for key in signal.init_data} | ||||||
|
||||||
for topic in event_type_publish_configs.keys(): | ||||||
if event_type_publish_configs[topic]["enabled"] is True: | ||||||
for topic in event_type_producer_configs.keys(): | ||||||
if event_type_producer_configs[topic]["enabled"] is True: | ||||||
get_producer().send( | ||||||
signal=signal, | ||||||
topic=topic, | ||||||
event_key_field=event_type_publish_configs[topic]["event_key_field"], | ||||||
event_key_field=event_type_producer_configs[topic]["event_key_field"], | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
event_data=event_data, | ||||||
event_metadata=kwargs["metadata"], | ||||||
) | ||||||
|
@@ -53,7 +53,7 @@ def _get_validated_signal_config(self, event_type, configuration): | |||||
Raises: | ||||||
ProducerConfigurationError: If configuration is not valid. | ||||||
""" | ||||||
if not isinstance(configuration, dict) and not isinstance(configuration, dict): | ||||||
if not isinstance(configuration, dict): | ||||||
raise ProducerConfigurationError( | ||||||
event_type=event_type, | ||||||
message="Configuration for event_types should be a dict" | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,26 +186,26 @@ def _reset_state(sender, **kwargs): # pylint: disable=unused-argument | |
get_producer.cache_clear() | ||
|
||
|
||
def merge_publisher_configs(publisher_config_original, publisher_config_overrides): | ||
def merge_producer_configs(producer_config_original, producer_config_overrides): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: renaming these variables to |
||
""" | ||
Merge two EVENT_BUS_PRODUCER_CONFIG maps. | ||
|
||
Arguments: | ||
publisher_config_original: An EVENT_BUS_PRODUCER_CONFIG-structured map | ||
publisher_config_overrides: An EVENT_BUS_PRODUCER_CONFIG-structured map | ||
producer_config_original: An EVENT_BUS_PRODUCER_CONFIG-structured map | ||
producer_config_overrides: An EVENT_BUS_PRODUCER_CONFIG-structured map | ||
|
||
Returns: | ||
A new EVENT_BUS_PRODUCER_CONFIG map created by combining the two maps. All event_type/topic pairs in | ||
publisher_config_b are added to the publisher_config_a. If there is a conflict on whether a particular | ||
event_type/topic pair is enabled, publisher_config_b wins out. | ||
publisher_config_overrides are added to the publisher_config_original. If there is a conflict on whether a | ||
robrap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
particular event_type/topic pair is enabled, publisher_config_overrides wins out. | ||
""" | ||
combined = copy.deepcopy(publisher_config_original) | ||
for event_type, event_type_config_b in publisher_config_overrides.items(): | ||
combined = copy.deepcopy(producer_config_original) | ||
for event_type, event_type_config_overrides in producer_config_overrides.items(): | ||
event_type_config_combined = combined.get(event_type, {}) | ||
for topic, topic_config_b in event_type_config_b.items(): | ||
for topic, topic_config_overrides in event_type_config_overrides.items(): | ||
topic_config_combined = event_type_config_combined.get(topic, {}) | ||
topic_config_combined['enabled'] = topic_config_b['enabled'] | ||
topic_config_combined['event_key_field'] = topic_config_b['event_key_field'] | ||
topic_config_combined['enabled'] = topic_config_overrides['enabled'] | ||
topic_config_combined['event_key_field'] = topic_config_overrides['event_key_field'] | ||
event_type_config_combined[topic] = topic_config_combined | ||
combined[event_type] = event_type_config_combined | ||
return combined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.