From ddefbbfcfb37840cdb46f3a23ebf00952c32238b Mon Sep 17 00:00:00 2001
From: Andreas <andreasv@fsmpi.rwth-aachen.de>
Date: Wed, 18 Jul 2018 16:49:48 +0200
Subject: [PATCH] moved firering of job handlers to jobmanagement

---
 jobmanagement.py | 9 +++++++++
 jobs.py          | 6 +-----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/jobmanagement.py b/jobmanagement.py
index dd14e3b..7c2ffa6 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 05c7620..d0fb57a 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:
-- 
GitLab