Merge branch 'master' into task/3772/hosting_billing_monthly_subscription

This commit is contained in:
PCoder 2017-09-16 14:45:34 +05:30
commit 7256160a7b
3 changed files with 26 additions and 8 deletions

View file

@ -2,6 +2,7 @@ from datetime import datetime
from celery.exceptions import MaxRetriesExceededError from celery.exceptions import MaxRetriesExceededError
from celery.utils.log import get_task_logger from celery.utils.log import get_task_logger
from celery import current_task
from django.conf import settings from django.conf import settings
from django.core.mail import EmailMessage from django.core.mail import EmailMessage
@ -48,6 +49,7 @@ def create_vm_task(self, vm_template_id, user, specs, template,
stripe_customer_id, billing_address_data, stripe_customer_id, billing_address_data,
billing_address_id, billing_address_id,
charge, cc_details): charge, cc_details):
logger.debug("Running create_vm_task on {}".format(current_task.request.hostname))
vm_id = None vm_id = None
try: try:
final_price = specs.get('price') final_price = specs.get('price')
@ -169,8 +171,8 @@ def create_vm_task(self, vm_template_id, user, specs, template,
email_data = { email_data = {
'subject': '{} CELERY TASK ERROR: {}'.format(settings.DCL_TEXT, 'subject': '{} CELERY TASK ERROR: {}'.format(settings.DCL_TEXT,
msg_text), msg_text),
'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, 'from_email': current_task.request.hostname,
'to': ['info@ungleich.ch'], 'to': settings.DCL_ERROR_EMAILS_TO_LIST,
'body': ',\n'.join(str(i) for i in self.request.args) 'body': ',\n'.join(str(i) for i in self.request.args)
} }
email = EmailMessage(**email_data) email = EmailMessage(**email_data)

View file

@ -173,7 +173,8 @@ TEMPLATES = [
os.path.join(PROJECT_DIR, 'nosystemd/templates/'), os.path.join(PROJECT_DIR, 'nosystemd/templates/'),
os.path.join(PROJECT_DIR, os.path.join(PROJECT_DIR,
'ungleich/templates/djangocms_blog/'), 'ungleich/templates/djangocms_blog/'),
os.path.join(PROJECT_DIR, 'ungleich/templates/cms/ungleichch'), os.path.join(PROJECT_DIR,
'ungleich/templates/cms/ungleichch'),
os.path.join(PROJECT_DIR, 'ungleich/templates/ungleich'), os.path.join(PROJECT_DIR, 'ungleich/templates/ungleich'),
os.path.join(PROJECT_DIR, os.path.join(PROJECT_DIR,
'ungleich_page/templates/ungleich_page'), 'ungleich_page/templates/ungleich_page'),
@ -562,6 +563,18 @@ CELERY_RESULT_SERIALIZER = 'json'
# CELERY_TIMEZONE = 'Europe/Zurich' # CELERY_TIMEZONE = 'Europe/Zurich'
CELERY_MAX_RETRIES = int_env('CELERY_MAX_RETRIES', 5) CELERY_MAX_RETRIES = int_env('CELERY_MAX_RETRIES', 5)
DCL_ERROR_EMAILS_TO = env('DCL_ERROR_EMAILS_TO')
DCL_ERROR_EMAILS_TO_LIST = []
if DCL_ERROR_EMAILS_TO is not None:
DCL_ERROR_EMAILS_TO_LIST = [x.strip() for x in
DCL_ERROR_EMAILS_TO.split(
',')] \
if "," in DCL_ERROR_EMAILS_TO else [DCL_ERROR_EMAILS_TO.strip()]
if 'info@ungleich.ch' not in DCL_ERROR_EMAILS_TO_LIST:
DCL_ERROR_EMAILS_TO_LIST.append('info@ungleich.ch')
ENABLE_DEBUG_LOGGING = bool_env('ENABLE_DEBUG_LOGGING') ENABLE_DEBUG_LOGGING = bool_env('ENABLE_DEBUG_LOGGING')
if ENABLE_DEBUG_LOGGING: if ENABLE_DEBUG_LOGGING:

View file

@ -3,6 +3,7 @@ import tempfile
import cdist import cdist
from cdist.integration import configure_hosts_simple from cdist.integration import configure_hosts_simple
from celery.result import AsyncResult from celery.result import AsyncResult
from celery import current_task
from celery.utils.log import get_task_logger from celery.utils.log import get_task_logger
from django.conf import settings from django.conf import settings
from django.core.mail import EmailMessage from django.core.mail import EmailMessage
@ -38,6 +39,8 @@ def save_ssh_key(self, hosts, keys):
'state': True # whether key is to be added or 'state': True # whether key is to be added or
} # removed } # removed
""" """
logger.debug(
"Running save_ssh_key on {}".format(current_task.request.hostname))
logger.debug("""Running save_ssh_key task for logger.debug("""Running save_ssh_key task for
Hosts: {hosts_str} Hosts: {hosts_str}
Keys: {keys_str}""".format(hosts_str=", ".join(hosts), Keys: {keys_str}""".format(hosts_str=", ".join(hosts),
@ -70,8 +73,8 @@ def save_ssh_key(self, hosts, keys):
email_data = { email_data = {
'subject': "celery save_ssh_key error - task id {0}".format( 'subject': "celery save_ssh_key error - task id {0}".format(
self.request.id.__str__()), self.request.id.__str__()),
'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, 'from_email': current_task.request.hostname,
'to': ['info@ungleich.ch'], 'to': settings.DCL_ERROR_EMAILS_TO_LIST,
'body': "Task Id: {0}\nResult: {1}\nTraceback: {2}".format( 'body': "Task Id: {0}\nResult: {1}\nTraceback: {2}".format(
self.request.id.__str__(), False, str(cdist_exception)), self.request.id.__str__(), False, str(cdist_exception)),
} }
@ -87,8 +90,8 @@ def save_ssh_key_error_handler(uuid):
uuid, exc, result.traceback)) uuid, exc, result.traceback))
email_data = { email_data = {
'subject': "[celery error] Save SSH key error {0}".format(uuid), 'subject': "[celery error] Save SSH key error {0}".format(uuid),
'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, 'from_email': current_task.request.hostname,
'to': ['info@ungleich.ch'], 'to': settings.DCL_ERROR_EMAILS_TO_LIST,
'body': "Task Id: {0}\nResult: {1}\nTraceback: {2}".format( 'body': "Task Id: {0}\nResult: {1}\nTraceback: {2}".format(
uuid, exc, result.traceback), uuid, exc, result.traceback),
} }