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

fixes transaction deadlocks causing exceptions

parent fccadfa4
No related branches found
No related tags found
No related merge requests found
...@@ -141,8 +141,10 @@ def jobs_schedule(hostname): ...@@ -141,8 +141,10 @@ def jobs_schedule(hostname):
if not hostdata: if not hostdata:
return 'no hostdata sent', 400 return 'no hostdata sent', 400
job = None job = None
tries = 0
jobtypes = hostdata['jobtypes'] if 'jobtypes' in hostdata else [] jobtypes = hostdata['jobtypes'] if 'jobtypes' in hostdata else []
while (not job): while (not job):
try:
query("BEGIN") query("BEGIN")
for i in query('SELECT * FROM jobs WHERE state = "ready" ORDER BY priority DESC'): for i in query('SELECT * FROM jobs WHERE state = "ready" ORDER BY priority DESC'):
if i['type'] in hostdata['jobtypes'] and \ if i['type'] in hostdata['jobtypes'] and \
...@@ -152,9 +154,12 @@ def jobs_schedule(hostname): ...@@ -152,9 +154,12 @@ def jobs_schedule(hostname):
if not job: if not job:
return 'no jobs', 503 return 'no jobs', 503
modify('UPDATE jobs SET state="scheduled", worker = ?, time_scheduled = ? WHERE id = ?', hostname, datetime.now(), job['id']) modify('UPDATE jobs SET state="scheduled", worker = ?, time_scheduled = ? WHERE id = ?', hostname, datetime.now(), job['id'])
try:
query("COMMIT") query("COMMIT")
except: except OperationalError:
tries += 1
job = None job = None
sleep(random.randinti(0,50)) sleep(random.randinti(0,50))
if tries > 10:
return 'no jobs', 503
return Response(json.dumps(job, default=date_json_handler), mimetype='application/json') return Response(json.dumps(job, default=date_json_handler), mimetype='application/json')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment