Skip to content

Conversation

@mariamjamal94
Copy link
Owner

@mariamjamal94 mariamjamal94 commented Aug 1, 2019

Summary

  • Add default event processor as forwarding_event_processor.
  • Integrate changes with optimizely.
  • Add validator that ensures that event_processor implements process method.

Test plan

  • Added unit tests.

@mariamjamal94 mariamjamal94 requested a review from mnoman09 August 1, 2019 12:44

def process(self, event):
if not isinstance(event, UserEvent):
# TODO: log error

Choose a reason for hiding this comment

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

hm... then write log. :)

Copy link

@msohailhussain msohailhussain left a 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

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.

Copy link
Owner Author

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:

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.

Copy link
Owner Author

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?

Copy link
Collaborator

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.

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

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.

error_handler=None,
skip_json_validation=False,
user_profile_service=None,
event_processor=None,

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,

Choose a reason for hiding this comment

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

Please check indentation.

notification_center=self.notification_center,
skip_json_validation=skip_json_validation)

# TODO: remove it and delete test_event_builder file

Choose a reason for hiding this comment

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

remove comment.

# 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)

Choose a reason for hiding this comment

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

call it log_event.

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__)

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):

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))

Choose a reason for hiding this comment

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

please remove.

mjamal@folio3.com and others added 23 commits August 9, 2019 11:07
…vent_processor

# Conflicts:
#	tests/test_event_processor.py
# Conflicts:
#	tests/test_event_payload.py
mjamal@folio3.com and others added 21 commits August 21, 2019 18:38
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants