Improve startup sequence

This commit is contained in:
allegroai 2020-08-24 14:05:48 +03:00
parent 0abfd8da0d
commit b93591ec32
2 changed files with 26 additions and 20 deletions

View File

@ -49,16 +49,17 @@ class ConnectionErrorFilter(logging.Filter):
self.last_blocked = None
def filter(self, record):
try:
allow = (
(self.err_type is None or record.exc_info[0] != self.err_type)
and (self.level is None or record.levelno != self.level)
and (self.args is None or record.args[: len(self.args)] != self.args)
)
if not allow:
self.last_blocked = record
return int(allow)
return allow
except Exception:
return True
def check_elastic_empty() -> bool:

View File

@ -57,21 +57,26 @@ with distributed_lock(key, timeout=config.get("apiserver.db_init_timout", 120)):
info.es_connection_error = True
empty_db = check_mongo_empty()
if upgrade_monitoring:
if not empty_db and (info.es_connection_error or empty_es):
if get_last_server_version() < Version("0.16.0"):
if (
upgrade_monitoring
and not empty_db
and (info.es_connection_error or empty_es)
and get_last_server_version() < Version("0.16.0")
):
log.info(f"ES database seems not migrated")
info.missed_es_upgrade = True
proceed_with_init = not (info.es_connection_error or info.missed_es_upgrade)
else:
proceed_with_init = True
if proceed_with_init:
if info.es_connection_error and not info.missed_es_upgrade:
raise Exception(
"Error starting server: failed connecting to ElasticSearch service"
)
if not info.missed_es_upgrade:
init_es_data()
init_mongo_data()
if (
proceed_with_init
not info.missed_es_upgrade
and empty_db
and config.get("apiserver.pre_populate.enabled", False)
):