Fix when the cache from jobs is saved into DB + sleep 5 seconds when waiting for the database for the UI

This commit is contained in:
Théophile Diot 2023-04-24 10:10:39 +02:00
parent d32102376f
commit f1a868c66b
No known key found for this signature in database
GPG key ID: E752C80DB72BB014
2 changed files with 5 additions and 6 deletions

View file

@ -4,7 +4,6 @@ from hashlib import sha512
from inspect import getsourcefile
from json import dumps, loads
from pathlib import Path
from shutil import copy
from sys import _getframe
from threading import Lock
from traceback import format_exc
@ -27,7 +26,7 @@ def is_cached_file(file: str, expire: str, db=None) -> bool:
if not db:
return False
cached_file = db.get_job_cache_file(
getsourcefile(_getframe(1)).replace(".py", ""),
getsourcefile(_getframe(1)).replace(".py", "").split("/")[-1],
file.split("/")[-1],
with_data=False,
)
@ -69,7 +68,7 @@ def cache_hash(cache: str, db=None) -> Optional[str]:
return loads(Path(f"{cache}.md").read_text()).get("checksum", None)
if db:
cached_file = db.get_job_cache_file(
getsourcefile(_getframe(1)).replace(".py", ""),
getsourcefile(_getframe(1)).replace(".py", "").split("/")[-1],
cache.split("/")[-1],
with_data=False,
)
@ -93,7 +92,7 @@ def cache_file(
if db:
with lock:
err = db.update_job_cache(
getsourcefile(_getframe(1)).replace(".py", ""),
getsourcefile(_getframe(1)).replace(".py", "").split("/")[-1],
service_id,
cache.split("/")[-1],
content,

View file

@ -28,14 +28,14 @@ class Config:
self.__logger.warning(
"Database is not initialized, retrying in 5s ...",
)
sleep(3)
sleep(5)
env = self.__db.get_config()
while not self.__db.is_first_config_saved() or not env:
self.__logger.warning(
"Database doesn't have any config saved yet, retrying in 5s ...",
)
sleep(3)
sleep(5)
env = self.__db.get_config()
self.__logger.info("Database is ready")