Added test case to check whether celery task executes properly on production.
This commit is contained in:
parent
e20d42e84b
commit
82b73df6e7
3 changed files with 141 additions and 17 deletions
|
|
@ -1,15 +1,17 @@
|
|||
from dynamicweb.celery import app
|
||||
from datetime import datetime
|
||||
|
||||
from celery.exceptions import MaxRetriesExceededError
|
||||
from celery.utils.log import get_task_logger
|
||||
from django.conf import settings
|
||||
from django.core.mail import EmailMessage
|
||||
|
||||
from dynamicweb.celery import app
|
||||
from hosting.models import HostingOrder, HostingBill
|
||||
from membership.models import StripeCustomer
|
||||
from opennebula_api.models import OpenNebulaManager
|
||||
from opennebula_api.serializers import VirtualMachineSerializer
|
||||
from hosting.models import HostingOrder, HostingBill
|
||||
from utils.forms import UserBillingAddressForm
|
||||
from datetime import datetime
|
||||
from membership.models import StripeCustomer
|
||||
from django.core.mail import EmailMessage
|
||||
from utils.models import BillingAddress
|
||||
from celery.exceptions import MaxRetriesExceededError
|
||||
|
||||
logger = get_task_logger(__name__)
|
||||
|
||||
|
|
@ -41,13 +43,15 @@ def retry_task(task, exception=None):
|
|||
|
||||
|
||||
@app.task(bind=True, max_retries=settings.CELERY_MAX_RETRIES)
|
||||
def create_vm_task(self, vm_template_id, user, specs, template, stripe_customer_id, billing_address_data,
|
||||
def create_vm_task(self, vm_template_id, user, specs, template,
|
||||
stripe_customer_id, billing_address_data,
|
||||
billing_address_id,
|
||||
charge):
|
||||
vm_id = None
|
||||
try:
|
||||
final_price = specs.get('price')
|
||||
billing_address = BillingAddress.objects.filter(id=billing_address_id).first()
|
||||
billing_address = BillingAddress.objects.filter(
|
||||
id=billing_address_id).first()
|
||||
customer = StripeCustomer.objects.filter(id=stripe_customer_id).first()
|
||||
# Create OpenNebulaManager
|
||||
manager = OpenNebulaManager(email=settings.OPENNEBULA_USERNAME,
|
||||
|
|
@ -114,7 +118,8 @@ def create_vm_task(self, vm_template_id, user, specs, template, stripe_customer_
|
|||
'subject': settings.DCL_TEXT + " Order from %s" % context['email'],
|
||||
'from_email': settings.DCL_SUPPORT_FROM_ADDRESS,
|
||||
'to': ['info@ungleich.ch'],
|
||||
'body': "\n".join(["%s=%s" % (k, v) for (k, v) in context.items()]),
|
||||
'body': "\n".join(
|
||||
["%s=%s" % (k, v) for (k, v) in context.items()]),
|
||||
'reply_to': [context['email']],
|
||||
}
|
||||
email = EmailMessage(**email_data)
|
||||
|
|
@ -124,11 +129,13 @@ def create_vm_task(self, vm_template_id, user, specs, template, stripe_customer_
|
|||
try:
|
||||
retry_task(self)
|
||||
except MaxRetriesExceededError:
|
||||
msg_text = 'Finished {} retries for create_vm_task'.format(self.request.retries)
|
||||
msg_text = 'Finished {} retries for create_vm_task'.format(
|
||||
self.request.retries)
|
||||
logger.error(msg_text)
|
||||
# Try sending email and stop
|
||||
email_data = {
|
||||
'subject': '{} CELERY TASK ERROR: {}'.format(settings.DCL_TEXT, msg_text),
|
||||
'subject': '{} CELERY TASK ERROR: {}'.format(settings.DCL_TEXT,
|
||||
msg_text),
|
||||
'from_email': settings.DCL_SUPPORT_FROM_ADDRESS,
|
||||
'to': ['info@ungleich.ch'],
|
||||
'body': ',\n'.join(str(i) for i in self.request.args)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue