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

E-mail administrator when a background action crashes

Closes #109.
parent 9a5722a6
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,9 @@ import logging
import os
from sqlalchemy import select
from sqlalchemy.orm import joinedload
import sys
import tempfile
from typing import Callable
import werkzeug.exceptions
import owl.assets as assets
......@@ -291,19 +293,26 @@ try:
# asynchronous evaluation. Each mule is notified by signals, but it wakes
# up and scans its queue occasionally in case a signal was lost.
def background_action(handler: Callable[[], None]) -> None:
try:
with app.app_context():
handler()
except Exception as e:
exc_info = sys.exc_info()
app.logger.error('Error when processing background action: %s', e, exc_info=exc_info)
owl.error_mail.log_exception(app, 'background', {}, exc_info)
# Mule 1
@timer(300, target='mule1')
def mule1_timer(signum):
app.logger.debug('Mule 1: Received timer tick')
with app.app_context():
owl.notify.send_notify()
background_action(owl.notify.send_notify)
@signal(42, target='mule1')
def mule1_signal(signum):
app.logger.debug('Mule 1: Received signal')
with app.app_context():
owl.notify.send_notify()
background_action(owl.notify.send_notify)
def wake_up_notify_mule():
app.logger.debug('Mule 1: Sending wakeup signal')
......@@ -314,14 +323,12 @@ try:
@timer(300, target='mule2')
def mule2_timer(signum):
app.logger.debug('Mule 2: Received timer tick')
with app.app_context():
owl.auto_eval.process_queue()
background_action(owl.auto_eval.process_queue)
@signal(43, target='mule2')
def mule2_signal(signum):
app.logger.debug('Mule 2: Received signal')
with app.app_context():
owl.auto_eval.process_queue()
background_action(owl.auto_eval.process_queue)
def wake_up_eval_mule():
app.logger.debug('Mule 2: Sending wakeup signal')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment