Michelle Wu
11/18/2020, 8:34 AMEmailTask in state_handlers . I want to receive a email message that shows task and new_state when failures occur. My handler looks something like this:
def email_on_failure(task, old_state, new_state):
if new_state.is_failed():
task = EmailTask(
subject="Prefect alert: {}".format(new_state),
msg = "Task: {}; New State: {}".format(task, new_state),
email_from='xxx',
email_to='xxx',
smtp_server='smtp.gmail.com',
smtp_port=xxx,
smtp_type='STARTTLS'
).run()
In tests, I can always receive the email with the correct subject, but the task and the new_state was always missing in the msg …Anyone has encountered similar problems?Jim Crist-Harif
11/18/2020, 11:26 PM<> brackets on the state as something? Try using html.escape to fix this:
import html
def email_on_failure(task, old_state, new_state):
if new_state.is_failed():
task = EmailTask(
subject="Prefect alert: {}".format(new_state),
msg = html.escape("Task: {}; New State: {}".format(task, new_state)),
email_from='xxx',
email_to='xxx',
smtp_server='<http://smtp.gmail.com|smtp.gmail.com>',
smtp_port=xxx,
smtp_type='STARTTLS'
).run()Michelle Wu
11/23/2020, 1:57 AM