platform
This commit is contained in:
parent
d9de00b873
commit
b662fc49d7
@ -18,6 +18,7 @@ class PlatformClient:
|
||||
self.configs_url = urllib.parse.urljoin(self.endpoint, 'configs/get')
|
||||
self.experiments_url = urllib.parse.urljoin(self.endpoint, 'experiments/get')
|
||||
self.staff_url = urllib.parse.urljoin(self.endpoint, 'is_staff')
|
||||
self.fetch_url = urllib.parse.urljoin(self.endpoint, 'fetch')
|
||||
self.config_storage = {}
|
||||
self.experiment_storage = {}
|
||||
self.poll_data()
|
||||
@ -28,14 +29,12 @@ class PlatformClient:
|
||||
def inner():
|
||||
while True:
|
||||
sleep(30)
|
||||
self.fetch_configs()
|
||||
self.fetch_experiments()
|
||||
self.fetch()
|
||||
|
||||
Thread(target=inner).start()
|
||||
|
||||
def poll_data(self):
|
||||
self.fetch_configs(with_exception=True)
|
||||
self.fetch_experiments(with_exception=True)
|
||||
self.fetch(with_exception=True)
|
||||
|
||||
def request_with_retries(self, url, params, with_exception=False, retries_count=3):
|
||||
exception_to_throw = None
|
||||
@ -58,6 +57,19 @@ class PlatformClient:
|
||||
if with_exception:
|
||||
raise exception_to_throw
|
||||
|
||||
def fetch(self, with_exception=False):
|
||||
if self.stage == 'local':
|
||||
local_platform = json.loads(open('local_platform.json', 'r').read())
|
||||
self.config_storage = local_platform['configs']
|
||||
self.experiment_storage = local_platform['experiments']
|
||||
return
|
||||
response_data = self.request_with_retries(self.fetch_url, {
|
||||
'project': self.app_name,
|
||||
'stage': self.stage,
|
||||
}, with_exception)
|
||||
self.config_storage = response_data['configs']
|
||||
self.experiment_storage = response_data['experiments']
|
||||
|
||||
def fetch_configs(self, with_exception=False):
|
||||
if self.stage == 'local':
|
||||
local_platform = json.loads(open('local_platform.json', 'r').read())
|
||||
|
Loading…
Reference in New Issue
Block a user