##// END OF EJS Templates
db: use asbool to detect if ping conenction or debug is set....
marcink -
r3301:1da16c19 stable
parent child Browse files
Show More
@@ -43,6 +43,7 b' import sqlalchemy.exc'
43 43 import sqlalchemy.sql
44 44 import webob
45 45 import pyramid.threadlocal
46 from pyramid.settings import asbool
46 47
47 48 import rhodecode
48 49 from rhodecode.translation import _, _pluralize
@@ -361,7 +362,8 b' def ping_connection(connection, branch):'
361 362 def engine_from_config(configuration, prefix='sqlalchemy.', **kwargs):
362 363 """Custom engine_from_config functions."""
363 364 log = logging.getLogger('sqlalchemy.engine')
364 _ping_connection = configuration.pop('sqlalchemy.db1.ping_connection', None)
365 use_ping_connection = asbool(configuration.pop('sqlalchemy.db1.ping_connection', None))
366 debug = asbool(configuration.get('debug'))
365 367
366 368 engine = sqlalchemy.engine_from_config(configuration, prefix, **kwargs)
367 369
@@ -370,12 +372,12 b' def engine_from_config(configuration, pr'
370 372 normal = '\x1b[0m'
371 373 return ''.join([color_seq, sql, normal])
372 374
373 if configuration['debug'] or _ping_connection:
375 if use_ping_connection:
376 log.debug('Adding ping_connection on the engine config.')
374 377 sqlalchemy.event.listen(engine, "engine_connect", ping_connection)
375 378
376 if configuration['debug']:
379 if debug:
377 380 # attach events only for debug configuration
378
379 381 def before_cursor_execute(conn, cursor, statement,
380 382 parameters, context, executemany):
381 383 setattr(conn, 'query_start_time', time.time())
@@ -394,10 +396,8 b' def engine_from_config(configuration, pr'
394 396 parameters, context, executemany):
395 397 delattr(conn, 'query_start_time')
396 398
397 sqlalchemy.event.listen(engine, "before_cursor_execute",
398 before_cursor_execute)
399 sqlalchemy.event.listen(engine, "after_cursor_execute",
400 after_cursor_execute)
399 sqlalchemy.event.listen(engine, "before_cursor_execute", before_cursor_execute)
400 sqlalchemy.event.listen(engine, "after_cursor_execute", after_cursor_execute)
401 401
402 402 return engine
403 403
General Comments 0
You need to be logged in to leave comments. Login now