update platform

This commit is contained in:
Administrator 2024-02-11 17:59:45 +03:00
parent f3602d5365
commit 12ce9b1906
2 changed files with 17 additions and 5 deletions

View File

@ -20,7 +20,7 @@ def main_keyboard(telegram_id):
def platform_staff(self):
return platform.is_staff(telegram_id=self.telegram_id)
user = User(telegram_id)
alice_exp_enabled = eval(alice_exp['condition'])
alice_exp_enabled = alice_exp['enabled'] and eval(alice_exp['condition'])
except Exception as exc:
logging.info(exc)
alice_exp_enabled = False

View File

@ -19,6 +19,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()
@ -29,14 +30,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
@ -59,6 +58,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())