markup/tasks.pm: add on_fail_handler(), add to process_message()

This commit is contained in:
2019-10-31 11:56:39 -07:00
parent b873327bee
commit 53e57abaec

View File

@ -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: