mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
First stab at mysql pools with context
This commit is contained in:
parent
89f1bc9d6d
commit
42dd4e6155
@ -158,7 +158,7 @@ def returners(opts, functions, whitelist=None, context=None):
|
|||||||
Returns the returner modules
|
Returns the returner modules
|
||||||
'''
|
'''
|
||||||
if context is None:
|
if context is None:
|
||||||
conext = {}
|
context = {}
|
||||||
return LazyLoader(_module_dirs(opts, 'returners', 'returner'),
|
return LazyLoader(_module_dirs(opts, 'returners', 'returner'),
|
||||||
opts,
|
opts,
|
||||||
tag='returner',
|
tag='returner',
|
||||||
|
@ -156,14 +156,26 @@ def _get_serv(ret=None, commit=False):
|
|||||||
Return a mysql cursor
|
Return a mysql cursor
|
||||||
'''
|
'''
|
||||||
_options = _get_options(ret)
|
_options = _get_options(ret)
|
||||||
try:
|
|
||||||
conn = MySQLdb.connect(host=_options.get('host'),
|
if __context__ and 'mysql_returner_conn' in __context__:
|
||||||
user=_options.get('user'),
|
log.debug('Reusing MySQL connection pool')
|
||||||
passwd=_options.get('pass'),
|
conn = __context__['mysql_returner_conn']
|
||||||
db=_options.get('db'),
|
else:
|
||||||
port=_options.get('port'))
|
log.debug('Generating new MySQL connection pool')
|
||||||
except MySQLdb.connections.OperationalError as exc:
|
try:
|
||||||
raise salt.exceptions.SaltMasterError('MySQL returner could not connect to database: {exc}'.format(exc=exc))
|
conn = MySQLdb.connect(host=_options.get('host'),
|
||||||
|
user=_options.get('user'),
|
||||||
|
passwd=_options.get('pass'),
|
||||||
|
db=_options.get('db'),
|
||||||
|
port=_options.get('port'),
|
||||||
|
pool_size=32)
|
||||||
|
|
||||||
|
try:
|
||||||
|
__context__['mysql_returner_conn'] = conn
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
except MySQLdb.connections.OperationalError as exc:
|
||||||
|
raise salt.exceptions.SaltMasterError('MySQL returner could not connect to database: {exc}'.format(exc=exc))
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
try:
|
try:
|
||||||
yield cursor
|
yield cursor
|
||||||
|
Loading…
Reference in New Issue
Block a user