Skip to content
Snippets Groups Projects
Commit 68509e96 authored by Andreas Valder's avatar Andreas Valder
Browse files

changed db wraper to always retry transactions for mysql

parent eda64713
No related branches found
No related tags found
No related merge requests found
......@@ -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()
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment