Skip to content
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: BatchEventProcessor as Default Event Processor #378

Merged
merged 8 commits into from
Jun 28, 2022
21 changes: 17 additions & 4 deletions optimizely/optimizely.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .decision_service import Decision
from .error_handler import NoOpErrorHandler as noop_error_handler
from .event import event_factory, user_event_factory
from .event.event_processor import ForwardingEventProcessor
from .event.event_processor import BatchEventProcessor
from .event_dispatcher import EventDispatcher as default_event_dispatcher
from .helpers import enums, validator
from .helpers.enums import DecisionSources
Expand All @@ -50,7 +50,8 @@ def __init__(
notification_center=None,
event_processor=None,
datafile_access_token=None,
default_decide_options=None
default_decide_options=None,
event_processor_options=None
):
""" Optimizely init method for managing Custom projects.

Expand Down Expand Up @@ -78,6 +79,7 @@ def __init__(
optimizely.event.event_processor.BatchEventProcessor.
datafile_access_token: Optional string used to fetch authenticated datafile for a secure project environment.
default_decide_options: Optional list of decide options used with the decide APIs.
event_processor_options: Optional dict of options to be passed to the default batch event processor.
"""
self.logger_name = '.'.join([__name__, self.__class__.__name__])
self.is_valid = True
Expand All @@ -86,8 +88,19 @@ def __init__(
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, logger=self.logger, notification_center=self.notification_center,
event_processor_defaults = {
'batch_size': 1,
'flush_interval': 30,
'timeout_interval': 5,
'start_on_init': True
}
if event_processor_options:
event_processor_defaults.update(event_processor_options)
self.event_processor = event_processor or BatchEventProcessor(
self.event_dispatcher,
logger=self.logger,
notification_center=self.notification_center,
**event_processor_defaults
)

if default_decide_options is None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_event_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class BatchEventProcessorTest(base.BaseTest):
MAX_BATCH_SIZE = 10
MAX_DURATION_SEC = 0.2
MAX_TIMEOUT_INTERVAL_SEC = 0.1
TEST_TIMEOUT = 10
TEST_TIMEOUT = 15

def setUp(self, *args, **kwargs):
base.BaseTest.setUp(self, 'config_dict_with_multiple_experiments')
Expand Down
Loading