예제 #1
0
    def test_get_data(self):
        service = "th_rss"

        self.assertTrue(service.startswith('th_'))

        service_long = MyService.full_name(service)

        self.assertTrue(service_long in settings.TH_SERVICES)

        self.assertTrue('publishing_limit' in settings.DJANGO_TH)
    def test_get_data(self):
        service = "th_rss"

        self.assertTrue(service.startswith('th_'))

        service_long = MyService.full_name(service)

        self.assertTrue(service_long in settings.TH_SERVICES)

        self.assertTrue('publishing_limit' in settings.DJANGO_TH)
예제 #3
0
    def get_data(service, cache_data, trigger_id):
        """
            get the data from the cache
            :param service: the service name
            :param cache_data: the data from the cache
            :type trigger_id: integer
            :return: Return the data from the cache
            :rtype: object
        """

        # rebuild the string
        # th_<service>.my_<service>.Service<Service>
        if service.startswith('th_'):
            service_long = MyService.full_name(service)
            # service_name = service.split('_')[1]
            # service_long = ''.join((service, ".my_", service_name, ".Service",
            #                        service_name.title()))
            # ... and check it
            if service_long in settings.TH_SERVICES:

                cache = caches[service]

                if 'publishing_limit' in settings.DJANGO_TH:
                    limit = settings.DJANGO_TH['publishing_limit']

                    # publishing of all the data
                    if limit == 0:
                        return cache_data
                    # or just a set of them
                    if cache_data is not None and len(cache_data) > limit:
                        for data in cache_data[limit:]:
                            service_str = ''.join(
                                (service, '_', str(trigger_id)))
                            # put that data in a version 2 of the cache
                            cache.set(service_str, data, version=2)
                            # delete data from cache version=1
                            # https://niwinz.github.io/django-redis/latest/#_scan_delete_keys_in_bulk
                            cache.delete_pattern(service_str)
                        # put in cache unpublished data
                        cache_data = cache_data[:limit]

        return cache_data
예제 #4
0
    def get_data(service, cache_data, trigger_id):
        """
            get the data from the cache
            :param service: the service name
            :param cache_data: the data from the cache
            :type trigger_id: integer
            :return: Return the data from the cache
            :rtype: object
        """

        # rebuild the string
        # th_<service>.my_<service>.Service<Service>
        if service.startswith('th_'):
            service_long = MyService.full_name(service)
            # service_name = service.split('_')[1]
            # service_long = ''.join((service, ".my_", service_name, ".Service",
            #                        service_name.title()))
            # ... and check it
            if service_long in settings.TH_SERVICES:

                cache = caches[service]

                if 'publishing_limit' in settings.DJANGO_TH:
                    limit = settings.DJANGO_TH['publishing_limit']

                    # publishing of all the data
                    if limit == 0:
                        return cache_data
                    # or just a set of them
                    if cache_data is not None and len(cache_data) > limit:
                        for data in cache_data[limit:]:
                            service_str = ''.join((service, '_',
                                                   str(trigger_id)))
                            # put that data in a version 2 of the cache
                            cache.set(service_str, data, version=2)
                            # delete data from cache version=1
                            # https://niwinz.github.io/django-redis/latest/#_scan_delete_keys_in_bulk
                            cache.delete_pattern(service_str)
                        # put in cache unpublished data
                        cache_data = cache_data[:limit]

        return cache_data
예제 #5
0
 def test_full_name(self):
     service_long = MyService.full_name('th_rss')
     self.assertEqual(self.full_name, service_long)
     self.assertTrue(service_long in settings.TH_SERVICES)