From 12ce9b1906643d0163000cfc4ab6fa045c532817 Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 11 Feb 2024 17:59:45 +0300 Subject: [PATCH] update platform --- helpers/keyboards.py | 2 +- helpers/sprint_platform.py | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/helpers/keyboards.py b/helpers/keyboards.py index 7876267..d47d3e4 100644 --- a/helpers/keyboards.py +++ b/helpers/keyboards.py @@ -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 diff --git a/helpers/sprint_platform.py b/helpers/sprint_platform.py index c55a015..72cad8d 100644 --- a/helpers/sprint_platform.py +++ b/helpers/sprint_platform.py @@ -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())