Пример #1
0
                                content_types[ctype_pk] = content_type

                            with transaction_atomic():
                                #save a new hit or increment this hits on an existing hit
                                hit, created = Hit.objects.select_for_update(
                                ).get_or_create(added=datetime.utcnow().date(),
                                                object_pk=object_pk,
                                                content_type=content_type)
                                if hit and created:
                                    hit.hits = long(count)
                                    hit.save()
                                elif hit:
                                    hit.hits = hit.hits + long(count)
                                    hit.save()

                        #reset the hitcount for this object to 0 - even if it was previously None
                        hitcount_cache.set(cache_key, 0,
                                           CACHED_HITCOUNT_CACHE_TIMEOUT)
                        #print  'reset key %s to zero = %s ' % (cache_key, hitcount_cache.get(cache_key))
            except Exception, ex:
                logger.error('Unable to persist hits')
                logger.error(ex)

                raise ex
            finally:
                release_lock()
        else:
            logger.error(
                'Unable to persist hits due to persist task already in progress (%s is locked)'
                % CACHED_HITCOUNT_LOCK_KEY)
Пример #2
0
                                content_type = ContentType.objects.get(id=ctype_pk)
                                content_types[ctype_pk] = content_type

                            with transaction_atomic():
                                #save a new hit or increment this hits on an existing hit
                                hit, created = Hit.objects.select_for_update().get_or_create(added=datetime.utcnow().date(), object_pk=object_pk, content_type=content_type)
                                if hit and created:
                                    hit.hits = long(count)
                                    hit.save()
                                elif hit:
                                    hit.hits = hit.hits + long(count)
                                    hit.save()

                        #reset the hitcount for this object to 0 - even if it was previously None
                        hitcount_cache.set(cache_key, 0, CACHED_HITCOUNT_CACHE_TIMEOUT)
                        #print  'reset key %s to zero = %s ' % (cache_key, hitcount_cache.get(cache_key))
            except Exception, ex:
                logger.error('Unable to persist hits')
                logger.error(ex)

                raise ex
            finally:
                release_lock()
        else:
            logger.error('Unable to persist hits due to persist task already in progress (%s is locked)' % CACHED_HITCOUNT_LOCK_KEY)





 def handle_noargs(self, **options):
     release_lock()