Skip to content
Snippets Groups Projects
Commit 2ab29f41 authored by Fabrice Le Goff's avatar Fabrice Le Goff
Browse files

make DB stuff in main thread conditionned to DB config

parent 69620f77
No related branches found
No related tags found
No related merge requests found
......@@ -115,7 +115,6 @@ if config.EmailLogList:
LogConfig.enable_mail_logging(config)
logger = LogConfig.enable_file_logging("main", "main.log", config)
dblogger = LogConfig.enable_file_logging("database", "database.log", config)
# Load filename parser
try:
......@@ -166,9 +165,11 @@ signal.signal(signal.SIGINT, main_exit)
logger.info(thread_id_string())
# Connect to database
db = None
db = checkDB(db, logger, dblogger, filename_parser, config)
db_last_connection_time = time()
if config.DBURL:
dblogger = LogConfig.enable_file_logging("database", "database.log", config)
db = None
db = checkDB(db, logger, dblogger, filename_parser, config)
db_last_connection_time = time()
# Setup Kerberos if needed
if config.Keytab:
......@@ -193,19 +194,20 @@ if config.DdmMonitoringEnabled:
while not exit_event.is_set():
logger.debug('checking DB connection')
db = checkDB(db, logger, dblogger, filename_parser, config)
# Always keep a fresh connection
if db and (time() - db_last_connection_time) > config.DBReconnectTimeout:
logger.info('refreshing database connection')
with db_lock:
try:
db.Reconnect()
except Exception as ex:
logger.error('error connecting to DB: %s', str(ex))
db = None
db_last_connection_time = time()
if config.DBURL:
logger.debug('checking DB connection')
db = checkDB(db, logger, dblogger, filename_parser, config)
# Always keep a fresh connection
if db and (time() - db_last_connection_time) > config.DBReconnectTimeout:
logger.info('refreshing database connection')
with db_lock:
try:
db.Reconnect()
except Exception as ex:
logger.error('error connecting to DB: %s', str(ex))
db = None
db_last_connection_time = time()
# Update KRB token, if needed:
if config.Keytab:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment