Skip to content

Commit 79f65ad

Browse files
authored
Merge pull request #206 from splitio/task/fixes
Task/fixes
2 parents 418b48e + d4860bc commit 79f65ad

17 files changed

Lines changed: 25 additions & 41 deletions

splitio/client/factory.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ def _build_in_memory_factory(api_key, cfg, sdk_url=None, events_url=None, # pyl
300300
),
301301
SegmentSynchronizationTask(
302302
synchronizers.segment_sync.synchronize_segments,
303-
synchronizers.segment_sync.worker_pool,
304303
cfg['segmentsRefreshRate'],
305304
),
306305
ImpressionsSyncTask(

splitio/sync/segment.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,12 @@ def __init__(self, segment_api, split_storage, segment_storage):
3030
self._worker_pool = workerpool.WorkerPool(10, self.synchronize_segment)
3131
self._worker_pool.start()
3232

33-
@property
34-
def worker_pool(self):
33+
def shutdown(self):
3534
"""
36-
Return worker_pool
37-
38-
:return: workerpool
39-
:rtype: splitio.tasks.util.WorkerPool
35+
Shutdown worker_pool
4036
4137
"""
42-
return self._worker_pool
38+
self._worker_pool.stop()
4339

4440
def synchronize_segment(self, segment_name, till=None):
4541
"""
@@ -78,8 +74,7 @@ def synchronize_segment(self, segment_name, till=None):
7874
segment_changes['till']
7975
)
8076

81-
if segment_changes['till'] == segment_changes['since'] \
82-
or (till is not None and segment_changes['till'] >= till):
77+
if segment_changes['till'] == segment_changes['since']:
8378
return
8479

8580
def synchronize_segments(self):

splitio/sync/split.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def synchronize_splits(self, till=None):
6060

6161
self._split_storage.set_change_number(split_changes['till'])
6262
if split_changes['till'] == split_changes['since'] \
63-
or (till is not None and split_changes['till'] >= till):
63+
and (till is None or split_changes['till'] >= till):
6464
return
6565

6666
def kill_split(self, split_name, default_treatment, change_number):

splitio/sync/synchronizer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,8 @@ def stop_periodic_fetching(self, shutdown=False):
272272
_LOGGER.debug('Stopping periodic fetching')
273273
self._split_tasks.split_task.stop()
274274
if shutdown: # stops task and worker pool
275-
self._split_tasks.segment_task.stop()
276-
else: # pauses task not worker pool
277-
self._split_tasks.segment_task.pause()
275+
self._split_synchronizers.segment_sync.shutdown()
276+
self._split_tasks.segment_task.stop()
278277

279278
def start_periodic_data_recording(self):
280279
"""Start recorders."""

splitio/tasks/segment_sync.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
from splitio.api import APIException
55
from splitio.tasks import BaseSynchronizationTask
6-
from splitio.tasks.util import asynctask, workerpool
6+
from splitio.tasks.util import asynctask
77

88

99
_LOGGER = logging.getLogger(__name__)
@@ -12,33 +12,23 @@
1212
class SegmentSynchronizationTask(BaseSynchronizationTask):
1313
"""Segment Syncrhonization class."""
1414

15-
def __init__(self, synchronize_segments, worker_pool, period):
15+
def __init__(self, synchronize_segments, period):
1616
"""
1717
Clas constructor.
1818
1919
:param synchronize_segments: handler for syncing segments
2020
:type synchronize_segments: func
2121
22-
:param worker_pool: worker created by sync to be able to stop worker
23-
:type worker_pool: splitio.tasks.util.WorkerPool
24-
2522
"""
26-
self._worker_pool = worker_pool
2723
self._task = asynctask.AsyncTask(synchronize_segments, period, on_init=None)
2824

2925
def start(self):
3026
"""Start segment synchronization."""
3127
self._task.start()
3228

33-
def pause(self):
34-
"""Pause segment synchronization."""
35-
self._task.stop()
36-
3729
def stop(self, event=None):
3830
"""Stop segment synchronization."""
39-
self._task.stop()
40-
if self._worker_pool is not None:
41-
self._worker_pool.stop(event)
31+
self._task.stop(event)
4232

4333
def is_running(self):
4434
"""

splitio/tasks/split_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, synchronize_splits, period):
2020
:type period: int
2121
"""
2222
self._period = period
23-
self._task = AsyncTask(synchronize_splits, period, on_init=synchronize_splits)
23+
self._task = AsyncTask(synchronize_splits, period, on_init=None)
2424

2525
def start(self):
2626
"""Start the task."""

tests/client/test_factory.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from splitio.client.config import DEFAULT_CONFIG
99
from splitio.storage import redis, inmemmory, uwsgi
1010
from splitio.tasks import events_sync, impressions_sync, split_sync, segment_sync, telemetry_sync
11-
from splitio.tasks.util import asynctask, workerpool
11+
from splitio.tasks.util import asynctask
1212
from splitio.api.splits import SplitsAPI
1313
from splitio.api.segments import SegmentsAPI
1414
from splitio.api.impressions import ImpressionsAPI
@@ -161,9 +161,8 @@ def _split_task_init_mock(self, synchronize_splits, period):
161161
segment_async_task_mock = mocker.Mock(spec=asynctask.AsyncTask)
162162
segment_async_task_mock.stop.side_effect = stop_mock
163163

164-
def _segment_task_init_mock(self, synchronize_segments, worker_pool, period):
164+
def _segment_task_init_mock(self, synchronize_segments, period):
165165
self._task = segment_async_task_mock
166-
self._worker_pool = mocker.Mock()
167166
self._period = period
168167
mocker.patch('splitio.client.factory.SegmentSynchronizationTask.__init__',
169168
new=_segment_task_init_mock)
@@ -256,9 +255,8 @@ def _split_task_init_mock(self, synchronize_splits, period):
256255
segment_async_task_mock = mocker.Mock(spec=asynctask.AsyncTask)
257256
segment_async_task_mock.stop.side_effect = stop_mock_2
258257

259-
def _segment_task_init_mock(self, synchronize_segments, worker_pool, period):
258+
def _segment_task_init_mock(self, synchronize_segments, period):
260259
self._task = segment_async_task_mock
261-
self._worker_pool = mocker.Mock()
262260
self._period = period
263261
mocker.patch('splitio.client.factory.SegmentSynchronizationTask.__init__',
264262
new=_segment_task_init_mock)
File renamed without changes.

tests/syncrhonizers/test_impressions_count_synchronizer.py renamed to tests/sync/test_impressions_count_synchronizer.py

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)