refresh configs

This commit is contained in:
Egor Svitin
2023-02-07 11:57:49 +03:00
parent 8ea0424242
commit 8f926f714b
3 changed files with 15 additions and 11 deletions

View File

@@ -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()