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

Maily o chybách: Napojení na joby

Closes #270.
parent 227408a2
No related branches found
No related tags found
1 merge request!120Mailové upozornění na interní chyby
This commit is part of merge request !120. Comments created here will be created in the context of that merge request.
......@@ -4,14 +4,16 @@ from datetime import timedelta
import os
import shutil
from sqlalchemy import or_
import sys
from typing import Optional, Dict, Callable, List
import mo
import mo.config as config
import mo.db as db
import mo.email
import mo.rights
import mo.util
from mo.util import logger
from mo.util import logger, ExceptionInfo
def send_notify():
......@@ -141,6 +143,8 @@ class TheJob:
job.out_file = None
sess.commit()
exc_info: ExceptionInfo = (None, None, None)
try:
self.gatekeeper = mo.rights.Gatekeeper(job.user)
self.expires_in_minutes = config.JOB_EXPIRATION
......@@ -159,7 +163,8 @@ class TheJob:
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)
exc_info = sys.exc_info()
logger.error(f'Job: Chyba při zpracování jobu #{job.job_id}: %s', e, exc_info=exc_info)
job.state = db.JobState.internal_error
job.result = 'Interní chyba, informujte prosím správce systému.'
......@@ -168,6 +173,16 @@ class TheJob:
job.expires_at = job.finished_at + timedelta(minutes=self.expires_in_minutes)
sess.commit()
# Maily o interních chybách posíláme mimo transakci
if job.state == db.JobState.internal_error:
err_attrs = {
'Job': f'#{job.job_id}',
'Type': str(job.type),
'User': f'#{job.user_id}',
'Desc': job.description,
}
mo.email.send_internal_error_email(f'Job #{job.job_id}', err_attrs, exc_info)
def process_jobs():
sess = db.get_session()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment