mail_on_failure: rewrite in python