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

moved firering of job handlers to jobmanagement

parent 1d32e6d8
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,15 @@ def job_handler(*types, state='finished'):
return func
return wrapper
def job_handler_handle(id, state):
job = query('SELECT * FROM jobs WHERE id = ?', id, nlfix=False)[0]
type = job['type']
for func in job_handlers.get(type, {}).get(state, []):
try:
func(id, job['type'], json.loads(job['data']), state, json.loads(job['status']))
except Exception:
traceback.print_exc()
@sched_func(10)
def job_catch_broken():
# scheduled but never pinged
......
......@@ -79,12 +79,8 @@ def jobs_ping(id):
query('UPDATE jobs SET time_finished = ?, status = ?, state = "finished" where id = ?', datetime.now(), status, id)
else:
query('UPDATE jobs SET worker = ?, last_ping = ?, status = ?, state = ? where id = ?', hostname, datetime.now(), status, state, id)
job_handler_handle(id, state)
job = query('SELECT * FROM jobs WHERE id = ?', id, nlfix=False)[0]
for func in job_handlers.get(job['type'], {}).get(state, []):
try:
func(id, job['type'], json.loads(job['data']), state, json.loads(job['status']))
except Exception:
traceback.print_exc()
if job['canceled']:
return 'Job canceled', 205
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment