Anand Doshi | 885e074 | 2015-03-03 14:55:30 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
Anand Doshi | de85a3a | 2014-07-22 19:48:26 +0530 | [diff] [blame] | 2 | # MIT License. See license.txt |
| 3 | |
| 4 | from __future__ import unicode_literals |
| 5 | import frappe |
| 6 | from frappe.celery_app import celery_task, task_logger |
| 7 | |
| 8 | @celery_task() |
Anand Doshi | 46256cd | 2014-08-27 12:23:52 +0530 | [diff] [blame] | 9 | def send_newsletter(site, newsletter, event): |
| 10 | # hack! pass event="bulk_long" to queue in longjob queue |
Anand Doshi | de85a3a | 2014-07-22 19:48:26 +0530 | [diff] [blame] | 11 | try: |
| 12 | frappe.connect(site=site) |
| 13 | doc = frappe.get_doc("Newsletter", newsletter) |
| 14 | doc.send_bulk() |
| 15 | |
| 16 | except: |
| 17 | frappe.db.rollback() |
| 18 | task_logger.warn(frappe.get_traceback()) |
| 19 | |
| 20 | # wasn't able to send emails :( |
| 21 | doc.db_set("email_sent", 0) |
| 22 | frappe.db.commit() |
| 23 | |
| 24 | raise |
| 25 | |
| 26 | else: |
| 27 | frappe.db.commit() |
| 28 | |
| 29 | finally: |
| 30 | frappe.destroy() |