From aa100d8b830f775a3eaa88a782f0f3faff2b0ca3 Mon Sep 17 00:00:00 2001
From: Martin Mares <mj@ucw.cz>
Date: Sat, 16 Jan 2021 15:02:28 +0100
Subject: [PATCH] =?UTF-8?q?Jobs:=20Pr=C3=A1ce=20s=20resulty?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 mo/jobs/__init__.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/mo/jobs/__init__.py b/mo/jobs/__init__.py
index b017d1c9..12f40be8 100644
--- a/mo/jobs/__init__.py
+++ b/mo/jobs/__init__.py
@@ -4,6 +4,7 @@ from datetime import timedelta
 import os
 import secrets
 from sqlalchemy import or_
+from sqlalchemy.orm import joinedload
 from typing import Optional, Dict, Callable, List
 
 import mo
@@ -116,17 +117,18 @@ class TheJob:
         try:
             _handler_table[job.type](self)
             if self.errors:
-                logger.info(f'Job: Neúspěšně dokončen job #{job.job_id}')
+                logger.info(f'Job: Neúspěšně dokončen job #{job.job_id} ({job.result})')
                 job.state = db.JobState.failed
                 job.out_json = {'errors': self.errors}
+                if job.result == "":
+                    job.result = 'Došlo k chybám, viz detail'
             else:
-                logger.info(f'Job: Úspěšně dokončen job #{job.job_id}')
+                logger.info(f'Job: Úspěšně dokončen job #{job.job_id} ({job.result})')
                 job.state = db.JobState.done
         except Exception as e:
             logger.error(f'Job: Chyba při zpracování jobu #{job.job_id}: %s', e, exc_info=e)
             job.state = db.JobState.failed
-            job.out_json = {'errors': 'Interní chyba, informujte prosím správce systému.'}
-            return
+            job.result = 'Interní chyba, informujte prosím správce systému.'
 
         job.finished_at = mo.util.get_now()
         job.expires_at = job.finished_at + timedelta(minutes=config.JOB_EXPIRATION)
-- 
GitLab