markup/tasks.pm: add on_fail_handler(), add to process_message()
This commit is contained in:
@ -19,14 +19,29 @@ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'procat2.settings')
|
|||||||
django.setup()
|
django.setup()
|
||||||
|
|
||||||
from .utils import clean_path, ensure_dir, set_file_perms, WORKDIR
|
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 .matching import find_marked_products
|
||||||
from .spreadsheet import write_spreadsheet
|
from .spreadsheet import write_spreadsheet
|
||||||
|
from procat2.settings import TREE_NAME
|
||||||
|
|
||||||
logger = get_task_logger(__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):
|
def process_message(path):
|
||||||
parser = FeedParser()
|
parser = FeedParser()
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
|
|||||||
Reference in New Issue
Block a user