Fixed job detail crash when running job is killed
[ais.git] / bin / jobrunner.py
index ab78eb93b3ee89ff4a3ed3ed8711e96918cdf753..31b493753e563504f6f1148f2aa30b01c6b53640 100755 (executable)
@@ -98,8 +98,15 @@ def runjob():
     dbcommit()
     logging.info('Job complete: result=%s', returncode)
 
-    sqlexec(u"INSERT INTO user_message (user_id, user_message_category_id, txt) VALUES(%(user_id)s, 'info', %(msg)s)", {'user_id':user_id, 'msg':('Your <a href="/job/%(jobid)s/download">job %(jobid)s</a> is complete.' % {'jobid': jobid}) })
-    dbcommit()
+    sqlexec(u'SELECT notify FROM job where id=%(jobid)s', {'jobid': jobid})
+    row = get_common_cursor().fetchone()
+    if row:
+        notify = row[0]
+        if notify == u'W':
+            sqlexec(u"INSERT INTO user_message (user_id, user_message_category_id, txt) VALUES(%(user_id)s, 'info', %(msg)s)", {'user_id':user_id, 'msg':('Your <a href="/job/%(jobid)s/download">job %(jobid)s</a> is complete.' % {'jobid': jobid}) })
+            sqlexec(u'UPDATE job SET notify=NULL WHERE id=%(jobid)s', {'jobid': jobid})
+            dbcommit()
+        # else SMS, Mail ...
 
     return True