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: ...@@ -115,7 +115,6 @@ if config.EmailLogList:
LogConfig.enable_mail_logging(config) LogConfig.enable_mail_logging(config)
logger = LogConfig.enable_file_logging("main", "main.log", config) logger = LogConfig.enable_file_logging("main", "main.log", config)
dblogger = LogConfig.enable_file_logging("database", "database.log", config)
# Load filename parser # Load filename parser
try: try:
...@@ -166,9 +165,11 @@ signal.signal(signal.SIGINT, main_exit) ...@@ -166,9 +165,11 @@ signal.signal(signal.SIGINT, main_exit)
logger.info(thread_id_string()) logger.info(thread_id_string())
# Connect to database # Connect to database
db = None if config.DBURL:
db = checkDB(db, logger, dblogger, filename_parser, config) dblogger = LogConfig.enable_file_logging("database", "database.log", config)
db_last_connection_time = time() db = None
db = checkDB(db, logger, dblogger, filename_parser, config)
db_last_connection_time = time()
# Setup Kerberos if needed # Setup Kerberos if needed
if config.Keytab: if config.Keytab:
...@@ -193,19 +194,20 @@ if config.DdmMonitoringEnabled: ...@@ -193,19 +194,20 @@ if config.DdmMonitoringEnabled:
while not exit_event.is_set(): while not exit_event.is_set():
logger.debug('checking DB connection') if config.DBURL:
db = checkDB(db, logger, dblogger, filename_parser, config) 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: # Always keep a fresh connection
logger.info('refreshing database connection') if db and (time() - db_last_connection_time) > config.DBReconnectTimeout:
with db_lock: logger.info('refreshing database connection')
try: with db_lock:
db.Reconnect() try:
except Exception as ex: db.Reconnect()
logger.error('error connecting to DB: %s', str(ex)) except Exception as ex:
db = None logger.error('error connecting to DB: %s', str(ex))
db_last_connection_time = time() db = None
db_last_connection_time = time()
# Update KRB token, if needed: # Update KRB token, if needed:
if config.Keytab: 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