Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions fbclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from fbclient.event_types import FlagEvent, Metric, MetricEvent, UserEvent
from fbclient.interfaces import DataUpdateStatusProvider
from fbclient.status import DataUpdateStatusProviderImpl
from fbclient.status_types import State
from fbclient.streaming import Streaming, _data_to_dict
from fbclient.update_processor import NullUpdateProcessor
from fbclient.utils import (cast_variation_by_flag_type, check_uwsgi, log,
Expand Down Expand Up @@ -67,7 +66,10 @@ def __init__(self, config: Config, start_wait: float = 15.):
raise ValueError("Config is not valid")

self._config = config
self._config.validate()
if self._config.is_offline:
log.info("FB Python SDK: SDK is in offline mode")
else:
self._config.validate()

# init components
# event processor
Expand All @@ -90,15 +92,11 @@ def __init__(self, config: Config, start_wait: float = 15.):
if not isinstance(self._update_processor, NullUpdateProcessor):
log.info("FB Python SDK: Waiting for Client initialization in %s seconds" % str(start_wait))

if isinstance(self._data_storage, NullDataStorage) or not self._data_storage.initialized:
if isinstance(self._data_storage, NullDataStorage) or (not self._data_storage.initialized and not self._config.is_offline):
log.warning("FB Python SDK: SDK just returns default variation because of no data found in the given environment")

update_processor_ready.wait(start_wait)
if self._config.is_offline:
log.info("FB Python SDK: SDK is in offline mode")
elif self._update_processor.initialized:
log.info("FB Python SDK: SDK initialization is completed")
else:
if not self._update_processor.initialized:
log.warning("FB Python SDK: SDK was not successfully initialized")
else:
log.info("FB Python SDK: SDK starts in asynchronous mode")
Expand Down Expand Up @@ -374,13 +372,10 @@ def initialize_from_external_json(self, json_str: str) -> bool:
:param json_str: feature flags, segments...etc in the json format
:return: True if the initialization is well done
"""
if self._config.is_offline and json_str:
if self._config.is_offline:
all_data = json.loads(json_str)
if valide_all_data(all_data):
version, data = _data_to_dict(all_data['data'])
res = self._update_status_provider.init(data, version)
if res:
self._update_status_provider.update_state(State.ok_state())
return res
return self._update_status_provider.init(data, version)

return False
3 changes: 3 additions & 0 deletions fbclient/update_processor.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from threading import Event
from fbclient.config import Config
from fbclient.interfaces import DataUpdateStatusProvider, UpdateProcessor
from fbclient.status_types import State


class NullUpdateProcessor(UpdateProcessor):

def __init__(self, config: Config, dataUpdateStatusProvider: DataUpdateStatusProvider, ready: Event):
self.__ready = ready
self.__store = dataUpdateStatusProvider

def start(self):
self.__ready.set()
self.__store.update_state(State.ok_state())

def stop(self):
pass
Expand Down
2 changes: 1 addition & 1 deletion fbclient/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "1.1.0"
VERSION = "1.1.1"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def parse_requirements(filename):
long_description_content_type='text/markdown',
install_requires=base_reqs,
classifiers=[
'Development Status :: 4 - Beta',
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
Expand Down
11 changes: 8 additions & 3 deletions tests/test_fbclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,20 @@ def start():
assert not client.initialize


def test_start_and_nowait():
with make_fb_client(NullUpdateProcessor, NullEventProcessor, start_wait=0) as client:
assert client.update_status_provider.wait_for_OKState(timeout=0.1)
assert client.initialize


@patch.object(NullUpdateProcessor, "start")
def test_start_and_nowait(mock_start_method):
def test_start_nowait_and_timeout(mock_start_method):
def start():
pass
mock_start_method.side_effect = start
with make_fb_client(NullUpdateProcessor, NullEventProcessor, start_wait=0) as client:
assert not client.initialize
sleep(0.1)
assert not client.update_status_provider.wait_for_OKState(timeout=0.1)
assert not client.initialize


@patch.object(NullUpdateProcessor, "start")
Expand Down