Browse Source

[minor] show queueing info for newsletter and commit

version-14
Rushabh Mehta 8 years ago
parent
commit
20aeaf0e4c
4 changed files with 62 additions and 14 deletions
  1. +10
    -4
      frappe/email/doctype/newsletter/newsletter.js
  2. +30
    -3
      frappe/email/doctype/newsletter/newsletter.json
  3. +2
    -1
      frappe/email/doctype/newsletter/newsletter.py
  4. +20
    -6
      frappe/email/queue.py

+ 10
- 4
frappe/email/doctype/newsletter/newsletter.js View File

@@ -21,9 +21,10 @@ cur_frm.cscript.refresh = function(doc) {
} }


cur_frm.cscript.setup_dashboard = function() { cur_frm.cscript.setup_dashboard = function() {
if(!cur_frm.doc.__islocal && cint(cur_frm.doc.email_sent) && cur_frm.doc.__onload && cur_frm.doc.__onload.status_count) {
if(!cur_frm.doc.__islocal && cint(cur_frm.doc.email_sent)
&& cur_frm.doc.__onload && cur_frm.doc.__onload.status_count) {
var stat = cur_frm.doc.__onload.status_count; var stat = cur_frm.doc.__onload.status_count;
var total = frappe.utils.sum($.map(stat, function(v) { return v; }));
var total = cur_frm.doc.scheduled_to_send;
if(total) { if(total) {
$.each(stat, function(k, v) { $.each(stat, function(k, v) {
stat[k] = flt(v * 100 / total, 2) + '%'; stat[k] = flt(v * 100 / total, 2) + '%';
@@ -31,12 +32,17 @@ cur_frm.cscript.setup_dashboard = function() {


cur_frm.dashboard.add_progress("Status", [ cur_frm.dashboard.add_progress("Status", [
{ {
title: stat["Sent"] + "% Sent",
title: stat["Not Sent"] + " Queued",
width: stat["Not Sent"],
progress_class: "progress-bar-info"
},
{
title: stat["Sent"] + " Sent",
width: stat["Sent"], width: stat["Sent"],
progress_class: "progress-bar-success" progress_class: "progress-bar-success"
}, },
{ {
title: stat["Sending"] + "% Sending",
title: stat["Sending"] + " Sending",
width: stat["Sending"], width: stat["Sending"],
progress_class: "progress-bar-warning" progress_class: "progress-bar-warning"
}, },


+ 30
- 3
frappe/email/doctype/newsletter/newsletter.json View File

@@ -124,6 +124,34 @@
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "scheduled_to_send",
"fieldtype": "Int",
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Scheduled To Send",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
@@ -275,7 +303,7 @@
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"menu_index": 0, "menu_index": 0,
"modified": "2016-12-29 14:40:10.027720",
"modified": "2017-01-19 06:16:23.102086",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Email", "module": "Email",
"name": "Newsletter", "name": "Newsletter",
@@ -285,13 +313,12 @@
"amend": 0, "amend": 0,
"apply_user_permissions": 0, "apply_user_permissions": 0,
"cancel": 0, "cancel": 0,
"create": 0,
"create": 1,
"delete": 1, "delete": 1,
"email": 1, "email": 1,
"export": 1, "export": 1,
"if_owner": 0, "if_owner": 0,
"import": 0, "import": 0,
"is_custom": 0,
"permlevel": 0, "permlevel": 0,
"print": 1, "print": 1,
"read": 1, "read": 1,


+ 2
- 1
frappe/email/doctype/newsletter/newsletter.py View File

@@ -40,7 +40,7 @@ class Newsletter(Document):
self.validate_send() self.validate_send()


# using default queue with a longer timeout as this isn't a scheduled task # using default queue with a longer timeout as this isn't a scheduled task
enqueue(send_newsletter, queue='default', timeout=5000, event='send_newsletter',
enqueue(send_newsletter, queue='default', timeout=6000, event='send_newsletter',
newsletter=self.name) newsletter=self.name)


else: else:
@@ -49,6 +49,7 @@ class Newsletter(Document):
frappe.msgprint(_("Scheduled to send to {0} recipients").format(len(self.recipients))) frappe.msgprint(_("Scheduled to send to {0} recipients").format(len(self.recipients)))


frappe.db.set(self, "email_sent", 1) frappe.db.set(self, "email_sent", 1)
frappe.db.set(self, 'scheduled_to_send', len(self.recipients))


def queue_all(self): def queue_all(self):
if not self.get("recipients"): if not self.get("recipients"):


+ 20
- 6
frappe/email/queue.py View File

@@ -125,6 +125,8 @@ def add(recipients, sender, subject, **kwargs):


if kwargs.get('now'): if kwargs.get('now'):
send_one(duplicate.name, now=True) send_one(duplicate.name, now=True)

frappe.db.commit()
else: else:
email_queue = get_email_queue(recipients, sender, subject, **kwargs) email_queue = get_email_queue(recipients, sender, subject, **kwargs)
if kwargs.get('now'): if kwargs.get('now'):
@@ -298,9 +300,15 @@ def make_cache_queue():
'''cache values in queue before sendign''' '''cache values in queue before sendign'''
cache = frappe.cache() cache = frappe.cache()


emails = frappe.db.sql('''select name from `tabEmail Queue`
where (status='Not Sent' or status='Partially Sent') and (send_after is null or send_after < %(now)s)
order by priority desc, creation asc
emails = frappe.db.sql('''select
name
from
`tabEmail Queue`
where
(status='Not Sent' or status='Partially Sent') and
(send_after is null or send_after < %(now)s)
order
by priority desc, creation asc
limit 500''', { 'now': now_datetime() }) limit 500''', { 'now': now_datetime() })


# reset value # reset value
@@ -311,9 +319,15 @@ def make_cache_queue():
def send_one(email, smtpserver=None, auto_commit=True, now=False, from_test=False): def send_one(email, smtpserver=None, auto_commit=True, now=False, from_test=False):
'''Send Email Queue with given smtpserver''' '''Send Email Queue with given smtpserver'''


email = frappe.db.sql('''select name, status, communication,
message, sender, reference_doctype, reference_name, unsubscribe_param, unsubscribe_method, expose_recipients, show_as_cc
from `tabEmail Queue` where name=%s for update''', email, as_dict=True)[0]
email = frappe.db.sql('''select
name, status, communication, message, sender, reference_doctype,
reference_name, unsubscribe_param, unsubscribe_method, expose_recipients,
show_as_cc
from
`tabEmail Queue`
where
name=%s
for update''', email, as_dict=True)[0]


recipients_list = frappe.db.sql('''select name, recipient, status from recipients_list = frappe.db.sql('''select name, recipient, status from
`tabEmail Queue Recipient` where parent=%s''',email.name,as_dict=1) `tabEmail Queue Recipient` where parent=%s''',email.name,as_dict=1)


Loading…
Cancel
Save