Пример #1
0
    def forwards(self, orm):
        "Write your forwards methods here."

        from djangodblog.helpers import construct_checksum

        for e in orm.Error.objects.all():
            orm.Error.objects.filter(pk=e.pk).update(checksum=construct_checksum(e))

        for e in orm.ErrorBatch.objects.all():
            orm.ErrorBatch.objects.filter(pk=e.pk).update(checksum=construct_checksum(e))
Пример #2
0
    def _create(self, **defaults):
        from models import Error, ErrorBatch
        
        URL_MAX_LENGTH = Error._meta.get_field_by_name('url')[0].max_length
        
        server_name = socket.gethostname()
        class_name  = defaults.pop('class_name', None)
        
        data = defaults.pop('data', {}) or {}
        if defaults.get('url'):
            data['url'] = defaults['url']
            defaults['url'] = defaults['url'][:URL_MAX_LENGTH]

        instance = Error(
            class_name=class_name,
            server_name=server_name,
            data=data,
            **defaults
        )
        instance.checksum = construct_checksum(instance)
        
        if settings.THRASHING_TIMEOUT and settings.THRASHING_LIMIT:
            cache_key = 'djangodblog:%s:%s' % (instance.class_name, instance.checksum)
            added = cache.add(cache_key, 1, settings.THRASHING_TIMEOUT)
            if not added and cache.incr(cache_key) > settings.THRASHING_LIMIT:
                return

        try:
            instance.save()
            batch, created = ErrorBatch.objects.get_or_create(
                class_name = class_name,
                server_name = server_name,
                checksum = instance.checksum,
                defaults = defaults
            )
            if not created:
                ErrorBatch.objects.filter(pk=batch.pk).update(
                    times_seen=models.F('times_seen') + 1,
                    status=0,
                    last_seen=datetime.datetime.now(),
                )
        except Exception, exc:
            try:
                logger.exception(u'Unable to process log entry: %s' % (exc,))
            except Exception, exc:
                warnings.warn(u'Unable to process log entry: %s' % (exc,))
Пример #3
0
    def _create(self, **defaults):
        from models import Error, ErrorBatch

        URL_MAX_LENGTH = Error._meta.get_field_by_name('url')[0].max_length

        server_name = socket.gethostname()
        class_name = defaults.pop('class_name', None)

        data = defaults.pop('data', {}) or {}
        if defaults.get('url'):
            data['url'] = defaults['url']
            defaults['url'] = defaults['url'][:URL_MAX_LENGTH]

        instance = Error(class_name=class_name,
                         server_name=server_name,
                         data=data,
                         **defaults)
        instance.checksum = construct_checksum(instance)

        if settings.THRASHING_TIMEOUT and settings.THRASHING_LIMIT:
            cache_key = 'djangodblog:%s:%s' % (instance.class_name,
                                               instance.checksum)
            added = cache.add(cache_key, 1, settings.THRASHING_TIMEOUT)
            if not added and cache.incr(cache_key) > settings.THRASHING_LIMIT:
                return

        try:
            instance.save()
            batch, created = ErrorBatch.objects.get_or_create(
                class_name=class_name,
                server_name=server_name,
                checksum=instance.checksum,
                defaults=defaults)
            if not created:
                ErrorBatch.objects.filter(pk=batch.pk).update(
                    times_seen=models.F('times_seen') + 1,
                    status=0,
                    last_seen=datetime.datetime.now(),
                )
        except Exception, exc:
            try:
                logger.exception(u'Unable to process log entry: %s' % (exc, ))
            except Exception, exc:
                warnings.warn(u'Unable to process log entry: %s' % (exc, ))
Пример #4
0
 def save(self, *args, **kwargs):
     if not self.checksum:
         self.checksum = construct_checksum(self)
     super(Error, self).save(*args, **kwargs)
Пример #5
0
 def save(self, *args, **kwargs):
     if not self.checksum:
         self.checksum = construct_checksum(self)
     super(Error, self).save(*args, **kwargs)