Skip to content

Commit

Permalink
Issue #139: 'Mail delivery may take too long under some circumstances'
Browse files Browse the repository at this point in the history
  • Loading branch information
CarolinaFernandez committed Apr 18, 2013
1 parent eb0bb83 commit 7420d65
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 deletions.
4 changes: 2 additions & 2 deletions expedient/src/python/expedient/clearinghouse/project/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
from expedient.common.permissions.models import ObjectPermission,\
PermissionOwnership, Permittee
from expedient.clearinghouse.project.forms import AddMemberForm, MemberForm
from expedient.common.utils.mail import send_mail # Wrapper for django.core.mail__send_mail
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
import uuid
from django.core.mail import send_mail
from django.conf import settings
from django.contrib.auth.models import User
import ldap
Expand Down Expand Up @@ -407,7 +407,7 @@ def add_member(request, proj_id):
recipient_list=[user.email],
)
except Exception as e:
print "User email notification could not be sent. Exception: %s" % str(e)
print "[WARNING] User e-mail notification could not be sent. Details: %s" % str(e)

return HttpResponseRedirect(reverse("project_detail", args=[proj_id]))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.db.models import signals
from expedient.common.messaging.models import DatedMessage
import traceback
from django.core.mail import send_mail
from expedient.common.utils.mail import send_mail # Wrapper for django.core.mail__send_mail
from django.conf import settings
from expedient.common.timer.models import Job
#from expedient.common.timer.exceptions import JobAlreadyScheduled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def save(self, domain_override=None, email_template_name='registration/password_
Generates a one-use only link for resetting password and sends to the user.
A minimal exception control is implemented to avoid problems with e-mail.
"""
from django.core.mail import send_mail
from expedient.common.utils.mail import send_mail # Wrapper for django.core.mail__send_mail
for user in self.users_cache:
if not domain_override:
current_site = Site.objects.get_current()
Expand Down
2 changes: 1 addition & 1 deletion expedient/src/python/expedient/common/messaging/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import models
from django.contrib.auth.models import User
from django.db.models import signals
from django.core.mail import send_mail
from expedient.common.utils.mail import send_mail # Wrapper for django.core.mail__send_mail
from django.conf import settings

class DatedMessageManager(models.Manager):
Expand Down
4 changes: 2 additions & 2 deletions expedient/src/python/expedient/common/messaging/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.views.generic import GenericViewError
from django.contrib import messages
from django.contrib.auth.models import User
from django.core.mail import send_mail
from expedient.common.utils.mail import send_mail # Wrapper for django.core.mail__send_mail
from django.conf import settings

def list_msgs(request, number=None):
Expand Down Expand Up @@ -99,7 +99,7 @@ def create_message(request, model=None, template_name=None,
#recipient_list=[settings.ROOT_EMAIL],
)
except Exception as e:
print "User email notification could no be sent"
print "[WARNING] User e-mail notification could not be sent. Details: %s" % str(e)

return create_update.redirect(post_save_redirect, new_object)
else:
Expand Down
28 changes: 28 additions & 0 deletions expedient/src/python/expedient/common/utils/mail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Functionality related to mail delivery.
@date: Apr 18, 2013
@author: CarolinaFernandez
"""

from django.core.mail import send_mail as django__send_mail
from ServiceThread import ServiceThread

def send_mail(subject, message, from_email, recipient_list):
"""
Wrapper for the send_mail method within django.core.mail
which uses a thread to decouple its execution from the
main program. This is specially useful if mail server
configuration is erroneus, server is very busy, etc; so
normal flow will not be affected.
"""
ServiceThread.start_method_new_thread(
django__send_mail,
None,
None,
subject,
message,
from_email,
recipient_list,
)

Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ def check_link_consistency(links, nodes, user, slice):

try:
from django.conf import settings
from expedient.common.utils.ServiceThread import ServiceThread
from django.core.mail import send_mail
from expedient.common.utils.mail import send_mail # Wrapper for django.core.mail__send_mail
# Use thread to avoid slow page load when server is unresponsive
ServiceThread.start_method_new_thread(send_mail, None, None, settings.EMAIL_SUBJECT_PREFIX + " Inconsistent links at slice '%s': Expedient" % str(slice.name), "Hi, Island Manager\n\nThis is a warning to notify about some inconsistent links within a topology. This may be happening because a plugin or Aggregate Manager references a node not present in the Aggregate Managers chosen for this slice.\n\nProject: %s\nSlice: %s\nProblematic links:\n\n%s" % (slice.project.name, slice.name, str(inconsistent_links)), settings.DEFAULT_FROM_EMAIL, [user.email],)
send_mail(settings.EMAIL_SUBJECT_PREFIX + " Inconsistent links at slice '%s': Expedient" % str(slice.name), "Hi, Island Manager\n\nThis is a warning to notify about some inconsistent links within a topology. This may be happening because a plugin or Aggregate Manager references a node not present in the Aggregate Managers chosen for this slice.\n\nProject: %s\nSlice: %s\nProblematic links:\n\n%s" % (slice.project.name, slice.name, str(inconsistent_links)), from_email = settings.DEFAULT_FROM_EMAIL, recipient_list = [user.email],)
except Exception as e:
print "[WARNING] Problem sending e-mail to user '%s' (email: %s) with information about link inconsistency inside TopologyGenerator. Details: %s" % (user.username, user.email, str(e))
return consistent_links
Expand Down

0 comments on commit 7420d65

Please sign in to comment.