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
Branches
No related tags found
No related merge requests found
......@@ -141,8 +141,10 @@ def jobs_schedule(hostname):
if not hostdata:
return 'no hostdata sent', 400
job = None
tries = 0
jobtypes = hostdata['jobtypes'] if 'jobtypes' in hostdata else []
while (not job):
try:
query("BEGIN")
for i in query('SELECT * FROM jobs WHERE state = "ready" ORDER BY priority DESC'):
if i['type'] in hostdata['jobtypes'] and \
......@@ -152,9 +154,12 @@ def jobs_schedule(hostname):
if not job:
return 'no jobs', 503
modify('UPDATE jobs SET state="scheduled", worker = ?, time_scheduled = ? WHERE id = ?', hostname, datetime.now(), job['id'])
try:
query("COMMIT")
except:
except OperationalError:
tries += 1
job = None
sleep(random.randinti(0,50))
if tries > 10:
return 'no jobs', 503
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