@@ -223,6 +223,17 @@ def __init__(self, split_synchronizers, split_tasks):
223223 """
224224 self ._split_synchronizers = split_synchronizers
225225 self ._split_tasks = split_tasks
226+ self ._periodic_data_recording_tasks = [
227+ self ._split_tasks .impressions_task ,
228+ self ._split_tasks .events_task
229+ ]
230+ if self ._split_tasks .impressions_count_task :
231+ self ._periodic_data_recording_tasks .append (self ._split_tasks .impressions_count_task )
232+ if self ._split_tasks .unique_keys_task is not None :
233+ self ._periodic_data_recording_tasks .append (self ._split_tasks .unique_keys_task )
234+ if self ._split_tasks .clear_filter_task is not None :
235+ self ._periodic_data_recording_tasks .append (self ._split_tasks .clear_filter_task )
236+
226237
227238 def _synchronize_segments (self ):
228239 _LOGGER .debug ('Starting segments synchronization' )
@@ -322,13 +333,8 @@ def stop_periodic_fetching(self):
322333 def start_periodic_data_recording (self ):
323334 """Start recorders."""
324335 _LOGGER .debug ('Starting periodic data recording' )
325- self ._split_tasks .impressions_task .start ()
326- self ._split_tasks .events_task .start ()
327- self ._split_tasks .impressions_count_task .start ()
328- if self ._split_tasks .unique_keys_task is not None :
329- self ._split_tasks .unique_keys_task .start ()
330- if self ._split_tasks .clear_filter_task is not None :
331- self ._split_tasks .clear_filter_task .start ()
336+ for task in self ._periodic_data_recording_tasks :
337+ task .start ()
332338
333339 def stop_periodic_data_recording (self , blocking ):
334340 """
@@ -340,28 +346,15 @@ def stop_periodic_data_recording(self, blocking):
340346 _LOGGER .debug ('Stopping periodic data recording' )
341347 if blocking :
342348 events = []
343- tasks = [self ._split_tasks .impressions_task ,
344- self ._split_tasks .events_task ,
345- self ._split_tasks .impressions_count_task ]
346- if self ._split_tasks .unique_keys_task is not None :
347- tasks .append (self ._split_tasks .unique_keys_task )
348- if self ._split_tasks .clear_filter_task is not None :
349- tasks .append (self ._split_tasks .clear_filter_task )
350-
351- for task in tasks :
349+ for task in self ._periodic_data_recording_tasks :
352350 stop_event = threading .Event ()
353351 task .stop (stop_event )
354352 events .append (stop_event )
355353 if all (event .wait () for event in events ):
356354 _LOGGER .debug ('all tasks finished successfully.' )
357355 else :
358- self ._split_tasks .impressions_task .stop ()
359- self ._split_tasks .events_task .stop ()
360- self ._split_tasks .impressions_count_task .stop ()
361- if self ._split_tasks .unique_keys_task is not None :
362- self ._split_tasks .unique_keys_task .stop ()
363- if self ._split_tasks .clear_filter_task is not None :
364- self ._split_tasks .clear_filter_task .stop ()
356+ for task in self ._periodic_data_recording_tasks :
357+ task .stop ()
365358
366359 def kill_split (self , split_name , default_treatment , change_number ):
367360 """
@@ -390,7 +383,13 @@ def __init__(self, split_synchronizers, split_tasks):
390383 :type split_tasks: splitio.sync.synchronizer.SplitTasks
391384 """
392385 self ._split_synchronizers = split_synchronizers
393- self ._split_tasks = split_tasks
386+ self ._tasks = []
387+ if split_tasks .impressions_count_task is not None :
388+ self ._tasks .append (split_tasks .impressions_count_task )
389+ if split_tasks .unique_keys_task is not None :
390+ self ._tasks .append (split_tasks .unique_keys_task )
391+ if split_tasks .clear_filter_task is not None :
392+ self ._tasks .append (split_tasks .clear_filter_task )
394393
395394 def sync_all (self ):
396395 """
@@ -411,11 +410,8 @@ def shutdown(self, blocking):
411410 def start_periodic_data_recording (self ):
412411 """Start recorders."""
413412 _LOGGER .debug ('Starting periodic data recording' )
414- self ._split_tasks .impressions_count_task .start ()
415- if self ._split_tasks .unique_keys_task is not None :
416- self ._split_tasks .unique_keys_task .start ()
417- if self ._split_tasks .clear_filter_task is not None :
418- self ._split_tasks .clear_filter_task .start ()
413+ for task in self ._tasks :
414+ task .start ()
419415
420416 def stop_periodic_data_recording (self , blocking ):
421417 """
@@ -427,23 +423,15 @@ def stop_periodic_data_recording(self, blocking):
427423 _LOGGER .debug ('Stopping periodic data recording' )
428424 if blocking :
429425 events = []
430- tasks = [self ._split_tasks .impressions_count_task ]
431- if self ._split_tasks .unique_keys_task is not None :
432- tasks .append (self ._split_tasks .unique_keys_task )
433- if self ._split_tasks .clear_filter_task is not None :
434- tasks .append (self ._split_tasks .clear_filter_task )
435- for task in tasks :
426+ for task in self ._tasks :
436427 stop_event = threading .Event ()
437428 task .stop (stop_event )
438429 events .append (stop_event )
439430 if all (event .wait () for event in events ):
440431 _LOGGER .debug ('all tasks finished successfully.' )
441432 else :
442- self ._split_tasks .impressions_count_task .stop ()
443- if self ._split_tasks .unique_keys_task is not None :
444- self ._split_tasks .unique_keys_task .stop ()
445- if self ._split_tasks .clear_filter_task is not None :
446- self ._split_tasks .clear_filter_task .stop ()
433+ for task in self ._tasks :
434+ task .stop ()
447435
448436 def kill_split (self , split_name , default_treatment , change_number ):
449437 """Kill a split locally."""
0 commit comments