diff --git a/markup/tasks.py b/markup/tasks.py index bc0b6af..afd672e 100644 --- a/markup/tasks.py +++ b/markup/tasks.py @@ -19,14 +19,29 @@ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'procat2.settings') django.setup() from .utils import clean_path, ensure_dir, set_file_perms, WORKDIR -from .email import reply, reply_missing, reply_no_matches +from .email import reply, reply_missing, reply_no_matches, send_error_email from .matching import find_marked_products from .spreadsheet import write_spreadsheet +from procat2.settings import TREE_NAME logger = get_task_logger(__name__) -@shared_task +def on_fail_handler(self, exc, task_id, args, kwargs, einfo): + """Send an email if a task throws an exception.""" + print(str(einfo)) + send_error_email(f'ERROR: {TREE_NAME} celery task {task_id}', str(einfo)) + + +# @shared_task(on_failure=on_fail_handler) +# def test_fail(x, y): +# test_fail_internal() + +# def test_fail_internal(): +# raise KeyError() + + +@shared_task(on_failure=on_fail_handler) def process_message(path): parser = FeedParser() with open(path) as f: