From 8f926f714b3033dd24cb25ef0f0a8e54d083504d Mon Sep 17 00:00:00 2001 From: Egor Svitin Date: Tue, 7 Feb 2023 11:57:49 +0300 Subject: [PATCH 1/2] refresh configs --- Dockerfile | 4 ---- configs/config.py | 17 +++++++++++------ update.py | 5 ++++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2c6d548..23d4cf5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,3 @@ COPY ./ ./ RUN chmod 777 /app/configs/sources.json -RUN python update.py --config - -RUN python update.py --source test - diff --git a/configs/config.py b/configs/config.py index af7f991..f0cfbf2 100644 --- a/configs/config.py +++ b/configs/config.py @@ -9,16 +9,18 @@ from configs.configs import CONFIGS class AppConfig: def __init__(self): - self.config = Dynaconf(settings_files=[ - "/app/configs/main.json", - "/app/configs/sources.json" - ]) - + self.refresh() connect( db=CONFIGS['db']['name'], host="mongodb://{host}:27017/{database}".format(host=CONFIGS['db']['host'], database=CONFIGS['db']['name']) ) - + + def refresh(self): + self.config = Dynaconf(settings_files=[ + "/app/configs/main.json", + "/app/configs/sources.json" + ]) + def get_bulk_insert_limit(self): if not self.config.bulk_limit: return 1 @@ -40,6 +42,7 @@ class AppConfig: } r = requests.get(CONFIGS['application_credentials']['api_url'] + "sources", headers=headers) if r.status_code != 200: + raise Exception('Bad app response') new_config = {"sources": {}} @@ -48,5 +51,7 @@ class AppConfig: with open("./configs/sources.json", "w") as outfile: outfile.write(json.dumps(new_config)) + + self.refresh() config = AppConfig() \ No newline at end of file diff --git a/update.py b/update.py index eecdbdb..913a1d0 100644 --- a/update.py +++ b/update.py @@ -34,14 +34,17 @@ class Updater: config.update_sources() def do_action(self): + print("Start Updater"); if self.args.config: + print("Start Configure") self.update_config() return if not self.is_source_exists(self.args.source): print("This source not exists, list of sources: " + ', '.join(config.get_sources_list())) return - + + print("Start source update") self.parse_source(self.args.source) From 14c011b921ab46bf4c9f601916c7ec79d72fa529 Mon Sep 17 00:00:00 2001 From: Egor Svitin Date: Tue, 7 Feb 2023 11:58:52 +0300 Subject: [PATCH 2/2] update whitespace --- update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.py b/update.py index 913a1d0..3edb210 100644 --- a/update.py +++ b/update.py @@ -44,7 +44,7 @@ class Updater: print("This source not exists, list of sources: " + ', '.join(config.get_sources_list())) return - print("Start source update") + print("Start source update") self.parse_source(self.args.source)