Added save_ssh_key_error_handler

This commit is contained in:
PCoder 2017-09-01 02:33:31 +05:30
parent a72287be5c
commit 1bc78ceb5d
2 changed files with 22 additions and 3 deletions

View file

@ -8,7 +8,7 @@ from oca.pool import WrongNameError, WrongIdError
from hosting.models import HostingOrder
from utils.models import CustomUser
from utils.tasks import save_ssh_key
from utils.tasks import save_ssh_key, save_ssh_key_error_handler
from .exceptions import KeyExistsError, UserExistsError, UserCredentialError
logger = logging.getLogger(__name__)
@ -553,7 +553,8 @@ class OpenNebulaManager():
hosts = self.get_all_hosts()
if len(hosts) > 0 and len(keys) > 0:
save_ssh_key.apply_async((hosts, keys), countdown=countdown)
save_ssh_key.apply_async((hosts, keys), countdown=countdown,
link_error=save_ssh_key_error_handler.s())
else:
logger.debug("Keys and hosts are empty, so not managing any keys")

View file

@ -1,6 +1,8 @@
import cdist
import tempfile
import cdist
from cdist.integration import configure_hosts_simple
from celery.result import AsyncResult
from celery.utils.log import get_task_logger
from django.conf import settings
from django.core.mail import EmailMessage
@ -66,3 +68,19 @@ def save_ssh_key(self, hosts, keys):
logger.error(cdist_exception)
return_value = False
return return_value
@app.task
def save_ssh_key_error_handler(uuid):
result = AsyncResult(uuid)
exc = result.get(propagate=False)
logger.error('Task {0} raised exception: {1!r}\n{2!r}'.format(
uuid, exc, result.traceback))
email_data = {
'subject': "[celery error] Save SSH key error {0}".format(uuid),
'from_email': settings.DCL_SUPPORT_FROM_ADDRESS,
'to': ['info@ungleich.ch'],
'body': "Task Id: {0}\nResult: {1}\nTraceback: {2}".format(
uuid, exc, result.traceback),
}
send_plain_email_task(email_data)