feat(event_processor): add forwarding event processor and integrate with optimizely.#3
Conversation
optimizely/event/event_processor.py
Outdated
|
|
||
| def process(self, event): | ||
| if not isinstance(event, UserEvent): | ||
| # TODO: log error |
|
|
||
| def __init__(self, event_dispatcher, logger, notification_center=None): | ||
| self.event_dispatcher = event_dispatcher | ||
| self.logger = logger |
There was a problem hiding this comment.
What if no logger or dispatcher is provided.
There was a problem hiding this comment.
Providing default_event_dispatcher and NoOpLogger as default values.
|
|
||
| log_event = EventFactory.create_log_event(event, self.logger) | ||
|
|
||
| if self.notification_center is not None: |
There was a problem hiding this comment.
I think this should be notified after dispatch_event.
There was a problem hiding this comment.
It is how we are doing in Java too. As soon as a log_event is created we send a notification.
@mnoman09 can you please give your input here?
There was a problem hiding this comment.
I think current code is fine.
Putting dispatchEvent before or after sending notification won't make any difference as we are handling the exception and logging.
optimizely/optimizely.py
Outdated
| from .config_manager import StaticConfigManager | ||
| from .config_manager import PollingConfigManager | ||
| from .error_handler import NoOpErrorHandler as noop_error_handler | ||
| from .event.event_factory import EventFactory |
There was a problem hiding this comment.
is it possible to make it one liner all imports. not sure but you may use * i think.
optimizely/optimizely.py
Outdated
| error_handler=None, | ||
| skip_json_validation=False, | ||
| user_profile_service=None, | ||
| event_processor=None, |
There was a problem hiding this comment.
don't add it in the middle, add it at the last arg.
| self.error_handler = error_handler or noop_error_handler | ||
| self.config_manager = config_manager | ||
| self.notification_center = notification_center or NotificationCenter(self.logger) | ||
| self.event_processor = event_processor or ForwardingEventProcessor(self.event_dispatcher, |
optimizely/optimizely.py
Outdated
| notification_center=self.notification_center, | ||
| skip_json_validation=skip_json_validation) | ||
|
|
||
| # TODO: remove it and delete test_event_builder file |
optimizely/optimizely.py
Outdated
| # This notification is deprecated and new Decision notifications | ||
| # are sent via their respective method calls. | ||
| if len(self.notification_center.notification_listeners[enums.NotificationTypes.ACTIVATE]) > 0: | ||
| impression_event = EventFactory.create_log_event(user_event, self.logger) |
optimizely/optimizely.py
Outdated
| if len(self.notification_center.notification_listeners[enums.NotificationTypes.TRACK]) > 0: | ||
| conversion_event = EventFactory.create_log_event(user_event, self.logger) | ||
| self.notification_center.send_notifications(enums.NotificationTypes.TRACK, event_key, user_id, | ||
| attributes, event_tags, conversion_event.__dict__) |
There was a problem hiding this comment.
call it log event to conversion_event
| ])) | ||
|
|
||
|
|
||
| class TestForwardingEventDispatcher(object): |
| self.assertTrue(isinstance(attributes, dict)) | ||
| self.assertTrue(isinstance(variation, entities.Variation)) | ||
| self.assertTrue(isinstance(event, event_builder.Event)) | ||
| # self.assertTrue(isinstance(event, event_builder.Event)) |
…vent_processor # Conflicts: # tests/test_event_processor.py
# Conflicts: # tests/test_event_payload.py
…into mnoman/log_event_notification # Conflicts: # tests/test_event_processor.py
…vent_processor # Conflicts: # optimizely/event/event_processor.py # optimizely/event/payload.py # tests/test_event_processor.py
…/python-sdk into mnoman/log_event_notification
Summary
Test plan