예제 #1
0
 def filter(cls, value):
     cls.debug('filtering on %s' % value)
     if cls._lookup is None:
         cls._get()
     if not isinstance(value, frozenset):
         value = Source.encode(value)
     return cls._lookup[value]
예제 #2
0
 def filter(cls, value):
     cls.debug('filtering on %s' % value)
     if cls._lookup is None:
         cls._get()
     if not isinstance(value, frozenset):
         value = Source.encode(value)
     return cls._lookup[value]
예제 #3
0
    def create(cls, name, source, sender, options=None,
               template=None, template_func=None, allow_global=False):
        """Create new ErrorHandler and its associated Destination."""
        destination = Destination.create(sender, options,
                                         template, template_func)

        # when called via Trigger classmethod source has already been encoded
        if not isinstance(source, frozenset):
            source = Source.encode(source)

        e = ErrorHandler(name=name, source=source, destination=destination,
                         allow_global=allow_global)
        e.save()
        return e
예제 #4
0
    def create(cls, name, source, sender, options=None,
               template=None, template_func=None, allow_global=False):
        """Create new ErrorHandler and its associated Destination."""
        destination = Destination.create(sender, options,
                                         template, template_func)

        # when called via Trigger classmethod source has already been encoded
        if not isinstance(source, frozenset):
            source = Source.encode(source)

        e = ErrorHandler(name=name, source=source, destination=destination,
                         allow_global=allow_global)
        e.save()
        return e
예제 #5
0
    def create(cls, source, trigger_func, params=None, **kwargs):
        """Create trigger against given source table.

        :param table source: Table object reference
        :param function trigger_func: function object to run for trigger
        :param dict params: optional additional parameters to pass to
            trigger_func
        """
        tfunc = Function(trigger_func, params=params)
        t = Trigger(name=kwargs.pop('name', Source.name(source)),
                    source=Source.encode(source),
                    trigger_func=tfunc,
                    **kwargs)
        t.save()
        return t
예제 #6
0
def process_data(sender, **kwargs):
    data = kwargs.pop('data')
    context = kwargs.pop('context')
    source = Source.get(context)

    logger.debug('Received post_data_save signal from %s context %s' %
                 (sender, context))

    triggers = TriggerCache.filter(Source.encode(source))
    if triggers:
        logger.debug('Found %d triggers.' % len(triggers))
        if callable(data):
            data = data()
        for t in triggers:
            TriggerThread(t, data, context).start()
예제 #7
0
    def create(cls, source, trigger_func, params=None, **kwargs):
        """Create trigger against given source table.

        :param table source: Table object reference
        :param function trigger_func: function object to run for trigger
        :param dict params: optional additional parameters to pass to
            trigger_func
        """
        tfunc = Function(trigger_func, params=params)
        t = Trigger(name=kwargs.pop('name', Source.name(source)),
                    source=Source.encode(source),
                    trigger_func=tfunc,
                    **kwargs)
        t.save()
        return t
예제 #8
0
def process_data(sender, **kwargs):
    data = kwargs.pop('data')
    context = kwargs.pop('context')
    source = Source.get(context)

    logger.debug('Received post_data_save signal from %s context %s' %
                 (sender, context))

    triggers = TriggerCache.filter(Source.encode(source))
    if triggers:
        logger.debug('Found %d triggers.' % len(triggers))
        if callable(data):
            data = data()
        for t in triggers:
            TriggerThread(t, data, context).start()
예제 #9
0
def process_error(sender, **kwargs):
    context = kwargs.pop('context')
    source = Source.get(context)

    logger.debug('Received error_signal from %s with context %s' %
                 (sender, context))

    handlers = ErrorHandlerCache.filter(Source.encode(source))
    logger.debug('Found %d handlers.' % len(handlers))
    event = Event(severity=ERROR_SEVERITY, context=context,
                  trigger_result=None)
    event.save()
    logger.debug('New Event created: %s' % event)
    for h in handlers:
        DestinationThread(h.destination, event, is_error=True).start()

    system_settings = SystemSettings.get_system_settings()
    if system_settings.global_error_handler:
        if not handlers or any([h.allow_global for h in handlers]):
            for d in GlobalErrorHandlerCache.data():
                DestinationThread(d, event, is_error=True).start()
예제 #10
0
def process_error(sender, **kwargs):
    context = kwargs.pop('context')
    source = Source.get(context)

    logger.debug('Received error_signal from %s with context %s' %
                 (sender, context))

    handlers = ErrorHandlerCache.filter(Source.encode(source))
    logger.debug('Found %d handlers.' % len(handlers))
    event = Event(severity=ERROR_SEVERITY, context=context,
                  trigger_result=None)
    event.save()
    logger.debug('New Event created: %s' % event)
    for h in handlers:
        DestinationThread(h.destination, event, is_error=True).start()

    system_settings = SystemSettings.get_system_settings()
    if system_settings.global_error_handler:
        if not handlers or any([h.allow_global for h in handlers]):
            for d in GlobalErrorHandlerCache.data():
                DestinationThread(d, event, is_error=True).start()