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]
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
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
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()
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()