Commit 68509e96 authored by Andreas Valder's avatar Andreas Valder

changed db wraper to always retry transactions for mysql

parent eda64713
......@@ -67,7 +67,15 @@ elif config['DB_ENGINE'] == 'mysql':
else:
db = mysql.connector.connect(user=config['MYSQL_USER'], password=config['MYSQL_PASSWD'], unix_socket=config.get('MYSQL_UNIX', None))
cur = db.cursor()
cur.execute(operation)
tries = 0
while (tries < 10):
try:
cur.execute(operation)
except mysql.connector.errors.InternalError as e:
if e.msg == 'Deadlock found when trying to get lock; try restarting transaction':
tries += 1
else:
raise
rows = []
try:
rows = cur.fetchall()
......
......@@ -155,10 +155,10 @@ def jobs_schedule(hostname):
return 'no jobs', 503
modify('UPDATE jobs SET state="scheduled", worker = ?, time_scheduled = ? WHERE id = ?', hostname, datetime.now(), job['id'])
query("COMMIT")
except OperationalError:
except:
tries += 1
job = None
sleep(random.randinti(0,50))
sleep(random.random())
if tries > 10:
return 'no jobs', 503
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment