Commit 131979e1 by Kevin Luo

Fix unicode username bug and use celery retry to get CourseEmail

 Remove username from email footer.
parent 4cc758da
...@@ -20,7 +20,7 @@ from mitxmako.shortcuts import render_to_string ...@@ -20,7 +20,7 @@ from mitxmako.shortcuts import render_to_string
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@task() @task(default_retry_delay=10, max_retries=5)
def delegate_email_batches(hash_for_msg, recipient, course_id, course_url, user_id): def delegate_email_batches(hash_for_msg, recipient, course_id, course_url, user_id):
''' '''
Delegates emails by querying for the list of recipients who should Delegates emails by querying for the list of recipients who should
...@@ -37,18 +37,11 @@ def delegate_email_batches(hash_for_msg, recipient, course_id, course_url, user_ ...@@ -37,18 +37,11 @@ def delegate_email_batches(hash_for_msg, recipient, course_id, course_url, user_
log.error("get_course_by_id failed: " + exc.args[0]) log.error("get_course_by_id failed: " + exc.args[0])
raise Exception("get_course_by_id failed: " + exc.args[0]) raise Exception("get_course_by_id failed: " + exc.args[0])
email = None
retries = 0
while email is None:
try: try:
email = CourseEmail.objects.get(hash=hash_for_msg) email = CourseEmail.objects.get(hash=hash_for_msg)
except CourseEmail.DoesNotExist as exc: except CourseEmail.DoesNotExist as exc:
if retries < 3: log.warning("Failed to get CourseEmail with hash %s, retry %d" % (hash_for_msg, current_task.request.retries))
retries += 1 raise delegate_email_batches.retry(arg=[hash_for_msg, recipient, course_id, course_url, user_id], exc=exc)
time.sleep(5)
else:
log.error("Failed to get CourseEmail with hash " + hash_for_msg + ", no workers fired.")
return 0
if recipient == "myself": if recipient == "myself":
recipient_qset = User.objects.filter(id=user_id).values('profile__name', 'email') recipient_qset = User.objects.filter(id=user_id).values('profile__name', 'email')
...@@ -140,7 +133,7 @@ def course_email(hash_for_msg, to_list, course_title, course_url, throttle=False ...@@ -140,7 +133,7 @@ def course_email(hash_for_msg, to_list, course_title, course_url, throttle=False
raise exc # this will cause the outer handler to catch the exception and retry the entire task raise exc # this will cause the outer handler to catch the exception and retry the entire task
else: else:
#this will fall through and not retry the message, since it will be popped #this will fall through and not retry the message, since it will be popped
log.warn('Email with hash ' + hash_for_msg + ' not delivered to ' + email + ' due to error: ' + exc.smtp_error) log.warning('Email with hash ' + hash_for_msg + ' not delivered to ' + email + ' due to error: ' + exc.smtp_error)
num_error += 1 num_error += 1
to_list.pop() to_list.pop()
......
<%! from django.core.urlresolvers import reverse %> <%! from django.core.urlresolvers import reverse %>
<br /> <br />
----<br /> ----<br />
This email was automatically sent from ${settings.PLATFORM_NAME} to ${name}. <br /> This email was automatically sent from ${settings.PLATFORM_NAME}. <br />
You are receiving this email at address ${ email } because you are enrolled in <a href="${course_url}">${ course_title }</a>.<br /> You are receiving this email at address ${ email } because you are enrolled in <a href="${course_url}">${ course_title }</a>.<br />
To stop receiving email like this, update your course email settings <a href="https://${settings.SITE_NAME}${reverse('dashboard')}">here</a>. <br /> To stop receiving email like this, update your course email settings <a href="https://${settings.SITE_NAME}${reverse('dashboard')}">here</a>. <br />
<%! from django.core.urlresolvers import reverse %> <%! from django.core.urlresolvers import reverse %>
---- ----
This email was automatically sent from ${settings.PLATFORM_NAME} to ${name}. This email was automatically sent from ${settings.PLATFORM_NAME}.
You are receiving this email at address ${ email } because you are enrolled in ${ course_title } You are receiving this email at address ${ email } because you are enrolled in ${ course_title }
(URL: ${course_url} ). (URL: ${course_url} ).
To stop receiving email like this, update your account settings at https://${settings.SITE_NAME}${reverse('dashboard')}. To stop receiving email like this, update your account settings at https://${settings.SITE_NAME}${reverse('dashboard')}.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment