Commit 26b16a86 authored by Andreas Valder's avatar Andreas Valder

fixes transaction deadlocks causing exceptions

parent fccadfa4
......@@ -141,20 +141,25 @@ 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):
query("BEGIN")
for i in query('SELECT * FROM jobs WHERE state = "ready" ORDER BY priority DESC'):
if i['type'] in hostdata['jobtypes'] and \
i['queue'] in hostdata['queues']:
job = i
break
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("BEGIN")
for i in query('SELECT * FROM jobs WHERE state = "ready" ORDER BY priority DESC'):
if i['type'] in hostdata['jobtypes'] and \
i['queue'] in hostdata['queues']:
job = i
break
if not job:
return 'no jobs', 503
modify('UPDATE jobs SET state="scheduled", worker = ?, time_scheduled = ? WHERE id = ?', hostname, datetime.now(), job['id'])
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')
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