Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
# Copyright 2020 TrilioData Inc.
# All Rights Reserved.

import inspect

import six

from contego.notifications.objects import base
from contego.objects import base as contego_base
from contego.objects import fields


@contego_base.NovaObjectRegistry.register_notification
class ExceptionPayload(base.NotificationPayloadBase):
    # Version 1.0: Initial version
    VERSION = '1.0'
    fields = {
        'module_name': fields.StringField(),
        'function_name': fields.StringField(),
        'exception': fields.StringField(),
        'exception_message': fields.StringField(),
        'traceback': fields.StringField()
    }

    def __init__(self, module_name, function_name, exception,
                 exception_message, traceback):
        super(ExceptionPayload, self).__init__()
        self.module_name = module_name
        self.function_name = function_name
        self.exception = exception
        self.exception_message = exception_message
        self.traceback = traceback

    @classmethod
    def from_exc_and_traceback(cls, fault, traceback):
        trace = inspect.trace()[-1]
        module = inspect.getmodule(trace[0])
        module_name = module.__name__ if module else 'unknown'
        return cls(
                function_name=trace[3],
                module_name=module_name,
                exception=fault.__class__.__name__,
                exception_message=six.text_type(fault),
                traceback=traceback)


@base.notification_sample('compute-exception.json')
@contego_base.ContegoObjectRegistry.register_notification
class ExceptionNotification(base.NotificationBase):
    # Version 1.0: Initial version
    VERSION = '1.0'
    fields = {
        'payload': fields.ObjectField('ExceptionPayload')
    }