Skip to content

Commit

Permalink
Merge 027f277 into b156e21
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaszurkan-optimizely committed Dec 16, 2019
2 parents b156e21 + 027f277 commit b2795f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions optimizely/event/event_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,13 @@ def flush(self):

def _flush_queue(self):
""" Flushes event_queue by dispatching events. """

if len(self._current_batch) == 0:
batch_len = len(self._current_batch)
if batch_len == 0:
self.logger.debug('Nothing to flush.')
return

self.logger.debug('Flushing batch size ' + str(batch_len))

with self.LOCK:
to_process_batch = list(self._current_batch)
self._current_batch = list()
Expand Down Expand Up @@ -267,6 +270,7 @@ def _add_to_batch(self, user_event):
user_event: UserEvent Instance.
"""
if self._should_split(user_event):
self.logger.debug('Flush on split.')
self._flush_queue()
self._current_batch = list()

Expand All @@ -277,6 +281,7 @@ def _add_to_batch(self, user_event):
with self.LOCK:
self._current_batch.append(user_event)
if len(self._current_batch) >= self.batch_size:
self.logger.debug('Flushing on batch size.')
self._flush_queue()

def _should_split(self, user_event):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_event_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def test_flush_once_max_timeout(self):
self.assertTrue(mock_config_logging.debug.called)
mock_config_logging.debug.assert_any_call('Received event of type ConversionEvent for user test_user.')
mock_config_logging.debug.assert_any_call('Flush interval deadline. Flushed queue.')
self.assertTrue(mock_config_logging.debug.call_count == 2)
mock_config_logging.debug.assert_any_call('Flushing batch size 1')
self.assertTrue(mock_config_logging.debug.call_count == 3)
self.optimizely.logger = SimpleLogger()

def test_flush_max_batch_size(self):
Expand Down

0 comments on commit b2795f2

Please sign in to comment.