brotherton-erpnext/erpnext/tasks.py

36 lines
754 B
Python
Raw Normal View History

# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2014-07-22 14:18:26 +00:00
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.celery_app import celery_task, task_logger
2015-12-24 09:43:54 +00:00
from frappe.utils.scheduler import log
2014-07-22 14:18:26 +00:00
@celery_task()
def send_newsletter(site, newsletter, event):
# hack! pass event="bulk_long" to queue in longjob queue
2014-07-22 14:18:26 +00:00
try:
frappe.connect(site=site)
doc = frappe.get_doc("Newsletter", newsletter)
doc.send_bulk()
except:
frappe.db.rollback()
2015-12-24 09:43:54 +00:00
task_logger.error(site)
task_logger.error(frappe.get_traceback())
2014-07-22 14:18:26 +00:00
# wasn't able to send emails :(
doc.db_set("email_sent", 0)
frappe.db.commit()
2015-12-24 09:43:54 +00:00
log("send_newsletter")
2014-07-22 14:18:26 +00:00
raise
else:
frappe.db.commit()
finally:
frappe.destroy()