mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
add blocking to db query
This commit is contained in:
@@ -52,7 +52,11 @@ log.info('INFO: Starting poller-service')
|
||||
class DB:
|
||||
conn = None
|
||||
|
||||
def __init__(self):
|
||||
self.in_use = False
|
||||
|
||||
def connect(self):
|
||||
self.in_use = True
|
||||
while True:
|
||||
try:
|
||||
self.conn.close()
|
||||
@@ -71,17 +75,24 @@ class DB:
|
||||
|
||||
self.conn.autocommit(True)
|
||||
self.conn.ping(True)
|
||||
self.in_use = False
|
||||
|
||||
def query(self, sql):
|
||||
while self.in_use:
|
||||
continue
|
||||
|
||||
self.in_use = True
|
||||
while True:
|
||||
try:
|
||||
cursor = self.conn.cursor()
|
||||
cursor.execute(sql)
|
||||
ret = cursor.fetchall()
|
||||
cursor.close()
|
||||
self.in_use = False
|
||||
return ret
|
||||
except (AttributeError, MySQLdb.OperationalError):
|
||||
log.warning('WARNING: MySQL Operational Error during query, reconnecting.')
|
||||
self.in_use = False
|
||||
self.connect()
|
||||
except (AttributeError, MySQLdb.ProgrammingError):
|
||||
log.warning('WARNING: MySQL Programming Error during query, attempting query again.')
|
||||
@@ -176,6 +187,11 @@ try:
|
||||
except KeyError:
|
||||
retry_query = 1
|
||||
|
||||
try:
|
||||
single_connection = bool(config['poller_service_single_connection'])
|
||||
except KeyError:
|
||||
single_connection = False
|
||||
|
||||
db = DB()
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user