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 self.last_blocked = None
def filter(self, record): def filter(self, record):
allow = ( try:
(self.err_type is None or record.exc_info[0] != self.err_type) allow = (
and (self.level is None or record.levelno != self.level) (self.err_type is None or record.exc_info[0] != self.err_type)
and (self.args is None or record.args[: len(self.args)] != self.args) 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: if not allow:
self.last_blocked = record self.last_blocked = record
return allow
return int(allow) except Exception:
return True
def check_elastic_empty() -> bool: 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 info.es_connection_error = True
empty_db = check_mongo_empty() empty_db = check_mongo_empty()
if upgrade_monitoring: if (
if not empty_db and (info.es_connection_error or empty_es): upgrade_monitoring
if get_last_server_version() < Version("0.16.0"): and not empty_db
log.info(f"ES database seems not migrated") and (info.es_connection_error or empty_es)
info.missed_es_upgrade = True and get_last_server_version() < Version("0.16.0")
proceed_with_init = not (info.es_connection_error or info.missed_es_upgrade) ):
else: log.info(f"ES database seems not migrated")
proceed_with_init = True info.missed_es_upgrade = 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_es_data()
init_mongo_data() init_mongo_data()
if ( if (
proceed_with_init not info.missed_es_upgrade
and empty_db and empty_db
and config.get("apiserver.pre_populate.enabled", False) and config.get("apiserver.pre_populate.enabled", False)
): ):