Skip to content
Snippets Groups Projects
Commit e08a2edf authored by Martin Mareš's avatar Martin Mareš
Browse files

Jobs: V průběhu jobu se sbírají hlášení o chybách

parent 5b166d74
Branches
No related tags found
3 merge requests!19Reforma vyhodnocování práv,!18Dávky okolo feedbacku,!17Výsledkovka pomocí mo.web.table
This commit is part of merge request !17. Comments created here will be created in the context of that merge request.
...@@ -4,7 +4,7 @@ from datetime import timedelta ...@@ -4,7 +4,7 @@ from datetime import timedelta
import os import os
import secrets import secrets
from sqlalchemy import or_ from sqlalchemy import or_
from typing import Optional, Dict, Callable from typing import Optional, Dict, Callable, List
import mo import mo
import mo.config as config import mo.config as config
...@@ -28,10 +28,12 @@ class TheJob: ...@@ -28,10 +28,12 @@ class TheJob:
job: db.Job job: db.Job
job_id: Optional[int] job_id: Optional[int]
errors: List[str]
def __init__(self, job_id: Optional[int] = None): def __init__(self, job_id: Optional[int] = None):
"""Pokud chceme pracovat s existujícím jobem, zadáme jeho ID.""" """Pokud chceme pracovat s existujícím jobem, zadáme jeho ID."""
self.job_id = job_id self.job_id = job_id
self.errors = []
def load(self) -> db.Job: def load(self) -> db.Job:
sess = db.get_session() sess = db.get_session()
...@@ -95,6 +97,9 @@ class TheJob: ...@@ -95,6 +97,9 @@ class TheJob:
logger.info(f'Job: Ruším job #{self.job.job_id}') logger.info(f'Job: Ruším job #{self.job.job_id}')
return self._finish_remove() return self._finish_remove()
def error(self, msg):
self.errors.append(msg)
def run(self): def run(self):
sess = db.get_session() sess = db.get_session()
if not self.load() or self.job.state != db.JobState.ready: if not self.load() or self.job.state != db.JobState.ready:
...@@ -110,11 +115,17 @@ class TheJob: ...@@ -110,11 +115,17 @@ class TheJob:
try: try:
_handler_table[job.type](self) _handler_table[job.type](self)
if self.errors:
logger.info(f'Job: Neúspěšně dokončen job #{job.job_id}')
job.state = db.JobState.failed
job.out_json = {'errors': self.errors}
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.state = db.JobState.done job.state = db.JobState.done
except Exception as e: except Exception as e:
logger.error(f'Job: Chyba při zpracování jobu #{job.job_id}: %s', e, exc_info=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.state = db.JobState.failed
job.out_json = {'errors': 'Interní chyba, informujte prosím správce systému.'}
return return
job.finished_at = mo.util.get_now() job.finished_at = mo.util.get_now()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment