diff --git a/jobmanagement.py b/jobmanagement.py index dd14e3b9ef0943edf7da28a7ba2ecb51a4b9cce9..7c2ffa6bb796f00afed8f09b32f605f4c8518b0d 100644 --- a/jobmanagement.py +++ b/jobmanagement.py @@ -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 diff --git a/jobs.py b/jobs.py index 05c762037d8c2d122cf02a7dc490df258fcbcda0..d0fb57a9175847d761f9221190759ab26e216627 100644 --- a/jobs.py +++ b/jobs.py @@ -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: