Skip to content

Commit

Permalink
fixup!: keep renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebecca Graber authored and Rebecca Graber committed Jan 24, 2024
1 parent 34f2300 commit 76f7ab7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions openedx_events/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ def get_source_name():
"""
Get the value that should be used for the source of an event.
"""
source = getattr(settings, "EVENT_BUS_SERVICE_NAME", None)
if not source:
source = getattr(settings, "SERVICE_VARIANT", None)
return source or ""
# .. setting_name: EVENTS_SERVICE_NAME
# .. setting_default: None
# .. setting_description: Identifier for the producing/consuming service of an event. Used in setting the source in
# the EventsMetadata. If not set, the EventsMetadata object will look for a SERVICE_VARIANT setting (usually only
# set for lms and cms). The full source will be set to openedx/<EVENTS_SERVICE_NAME or SERVICE_VARIANT>/web.
# If neither variable is set, the source will be "unidentified."
return getattr(settings, "EVENTS_SERVICE_NAME", None) or getattr(settings, "SERVICE_VARIANT", None)


@attr.s(frozen=True)
Expand Down Expand Up @@ -72,7 +75,8 @@ class EventsMetadata:
source = attr.ib(
type=str, default=None,
converter=attr.converters.default_if_none(
attr.Factory(lambda: "openedx/{service}/web".format(service=get_source_name()))
attr.Factory(lambda: "openedx/{service}/web".format(service=get_source_name()) if get_source_name()
else "unidentified")
),
validator=attr.validators.instance_of(str),
)
Expand Down
4 changes: 2 additions & 2 deletions openedx_events/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ def test_events_metadata_to_and_from_json(self):
@ddt.data(
('settings_variant', None, 'openedx/settings_variant/web'),
(None, 'my_service', 'openedx/my_service/web'),
(None, None, 'openedx//web'),
(None, None, 'unidentified'),
('settings_variant', 'my_service', 'openedx/my_service/web')
)
@ddt.unpack
def test_events_metadata_source(self, settings_variant, event_bus_service_name, expected_source):
with override_settings(
SERVICE_VARIANT=settings_variant,
EVENT_BUS_SERVICE_NAME=event_bus_service_name,
EVENTS_SERVICE_NAME=event_bus_service_name,
):
metadata = EventsMetadata(
event_type='test_type'
Expand Down

0 comments on commit 76f7ab7

Please sign in to comment.