moved to wrap_exception decorator
This commit is contained in:
@@ -81,11 +81,17 @@ def wrap_db_error(f):
|
||||
_wrap.func_name = f.func_name
|
||||
|
||||
|
||||
def wrap_exception(f):
|
||||
def wrap_exception(f, notifier=None, publisher_id=None, level=None):
|
||||
def _wrap(*args, **kw):
|
||||
try:
|
||||
return f(*args, **kw)
|
||||
except Exception, e:
|
||||
if notifier != None and 'safe_notify' in notifier.dir():
|
||||
event_type = f.__name__
|
||||
payload = dict(args=args, exception=e)
|
||||
payload.update(kw)
|
||||
notifier.safe_notify(publisher_id, event_type, level, payload)
|
||||
|
||||
if not isinstance(e, Error):
|
||||
#exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
LOG.exception(_('Uncaught exception'))
|
||||
|
@@ -43,11 +43,6 @@ def publisher_id(service, host=None):
|
||||
return "%s.%s" % (service, host)
|
||||
|
||||
|
||||
def msgkeys(event_type, instance_id, level, publisher_id):
|
||||
return dict(event_type=event_type, instance_id=instance_id,
|
||||
notification_level=level, publisher_id=publisher_id)
|
||||
|
||||
|
||||
def safe_notify(publisher_id, event_type, priority, payload):
|
||||
try:
|
||||
notify(publisher_id, event_type, notification_level, payload)
|
||||
@@ -55,27 +50,6 @@ def safe_notify(publisher_id, event_type, priority, payload):
|
||||
LOG.exception(_("Problem '%(e)' attempting to "
|
||||
"send to notification system." % locals()))
|
||||
|
||||
|
||||
def instance_safe_notify(publisher_id, event_type, priority, instance_id,
|
||||
extra_payload=None):
|
||||
payload = dict(instance_id = instance_id)
|
||||
if extra_payload:
|
||||
payload.extend(extra_payload)
|
||||
safe_notify(publisher_id, event_type, priority, payload)
|
||||
|
||||
|
||||
def exception_to_notification(self, ex):
|
||||
required = ['instance_id', 'publisher_id', 'notification_level',
|
||||
'event_type']
|
||||
for key in required:
|
||||
if not (hasattr(ex, key) and ex.key):
|
||||
return # Doesn't have everything we need. Skip it.
|
||||
instance_id = ex.instance_id
|
||||
publisher_id = ex.publisher_id
|
||||
notification_level = ex.notification_level
|
||||
event_type = ex.event_type
|
||||
instance_safe_notify(publisher_id, event_type, priority, instance_id)
|
||||
|
||||
def notify(publisher_id, event_type, priority, payload):
|
||||
"""
|
||||
Sends a notification using the specified driver
|
||||
|
@@ -44,7 +44,6 @@ from nova import fakerabbit
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova import utils
|
||||
from nova.notifier import api as notifier
|
||||
|
||||
|
||||
LOG = logging.getLogger('nova.rpc')
|
||||
@@ -313,7 +312,6 @@ class ConsumerSet(object):
|
||||
if not it:
|
||||
break
|
||||
while True:
|
||||
ex = None
|
||||
try:
|
||||
it.next()
|
||||
except StopIteration:
|
||||
@@ -321,13 +319,7 @@ class ConsumerSet(object):
|
||||
except greenlet.GreenletExit:
|
||||
running = False
|
||||
break
|
||||
except exception.NovaException, e:
|
||||
ex = e
|
||||
notifier.exception_to_notification(e)
|
||||
except Exception as e:
|
||||
ex = e
|
||||
|
||||
if ex:
|
||||
LOG.exception(_("Exception while processing consumer"))
|
||||
self.reconnect()
|
||||
# Break to outer loop
|
||||
|
Reference in New Issue
Block a user