diff --git a/project/commons/utils.py b/project/commons/utils.py index f6b24d1..3d19a11 100644 --- a/project/commons/utils.py +++ b/project/commons/utils.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- import datetime +import traceback + +from django.core.mail import mail_admins # convert datetime to json @@ -17,3 +20,7 @@ def safe_int(value, default=None): def only_numerics(value): """Убирает из переданной строки все не цифровые символы.""" return u''.join(c for c in value if c.isdigit()) + + +def mail_exception(subject, message, e): + return mail_admins(subject, u'%s\n\n%s' % (message, traceback.format_exc(e),)) diff --git a/project/customer/context_processors.py b/project/customer/context_processors.py index fb73d6c..b991b72 100644 --- a/project/customer/context_processors.py +++ b/project/customer/context_processors.py @@ -1,18 +1,17 @@ # -*- coding: utf-8 -*- -import traceback from datetime import datetime, timedelta from django.core.cache import cache -from django.core.mail import mail_admins from django.conf import settings +from project.commons.utils import mail_exception + from .models import License from . import consts DEBUG = getattr(settings, 'DEBUG', False) - cache_duration = 3600 @@ -66,8 +65,6 @@ def license_check_soon_ends(request): if DEBUG: raise else: - mail_admins(subject=u'customer: license_check_soon_ends error', - message=u'Profile id=%s.\n\n%s' % (request.user.profile.pk, traceback.format_exc(e)) - ) + mail_exception(u'customer: license_check_soon_ends error', u'Profile id=%d.' % request.user.profile.pk, e) # return { } diff --git a/project/customer/tasks.py b/project/customer/tasks.py index 139ae67..d67d58c 100644 --- a/project/customer/tasks.py +++ b/project/customer/tasks.py @@ -2,11 +2,11 @@ from __future__ import absolute_import from datetime import datetime, timedelta -import traceback -from django.core.mail import mail_admins from celery import shared_task +from project.commons.utils import mail_exception + from project.customer.models import License, UserProfile from project.customer.utils import check_one_profile from project.customer import consts @@ -29,8 +29,6 @@ def check_license(): try: check_one_profile(profile, License, now_) except Exception as e: - mail_admins(subject=u'customer: check_license error', - message=u'Profile id=%s.\n\n%s' % (profile.pk, traceback.format_exc(e)) - ) + mail_exception(u'customer: check_license error', u'Profile id=%d.' % profile.pk, e) return None