-
Notifications
You must be signed in to change notification settings - Fork 0
feat(event_processor): add forwarding event processor and integrate with optimizely. #3
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
base: mjamal/log_event_notification
Are you sure you want to change the base?
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 |
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.
hm... then write log. :)
msohailhussain
left a comment
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.
please address comments.
|
|
||
| def __init__(self, event_dispatcher, logger, notification_center=None): | ||
| self.event_dispatcher = event_dispatcher | ||
| self.logger = logger |
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.
What if no logger or dispatcher is provided.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be notified after dispatch_event.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
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.
Please check indentation.
optimizely/optimizely.py
Outdated
| notification_center=self.notification_center, | ||
| skip_json_validation=skip_json_validation) | ||
|
|
||
| # TODO: remove it and delete test_event_builder file |
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.
remove comment.
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) |
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.
call it log_event.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call it log event to conversion_event
| ])) | ||
|
|
||
|
|
||
| class TestForwardingEventDispatcher(object): |
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.
ForwardingEventProcessor
| 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)) |
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.
please remove.
…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