Example #1
0
    def test_fetch_poll_results(self):
        with self.settings(CACHES = {'default': {'BACKEND': 'redis_cache.cache.RedisCache',
                                                 'LOCATION': '127.0.0.1:6379:1',
                                                 'OPTIONS': {
                                                     'CLIENT_CLASS': 'redis_cache.client.DefaultClient',
                                                 }
                                                 }}):
            with patch('ureport.polls.models.Poll.fetch_poll_results') as mock_poll_model_fetch_results:
                mock_poll_model_fetch_results.return_value = "DONE"

                polls = [self.poll]
                _fetch_org_polls_results(self.org, polls)
                mock_poll_model_fetch_results.assert_called_with()
                mock_poll_model_fetch_results.mock_reset()

            with patch('ureport.polls.models.Poll.get_main_poll') as mock_main_poll:
                mock_main_poll.return_value = self.poll

                fetch_main_poll_results(self.org)
                mock_poll_model_fetch_results.assert_called_once_with()
                mock_poll_model_fetch_results.mock_reset()

            with patch('ureport.polls.models.Poll.get_brick_polls') as mock_brick_polls:
                mock_brick_polls.return_value = [self.poll]

                fetch_brick_polls_results(self.org)
                mock_poll_model_fetch_results.assert_called_once_with()
                mock_poll_model_fetch_results.mock_reset()

            with patch('ureport.polls.models.Poll.get_other_polls') as mock_other_polls:
                mock_other_polls.return_value = [self.poll]

                fetch_other_polls_results(self.org)
                mock_poll_model_fetch_results.assert_called_once_with()
                mock_poll_model_fetch_results.mock_reset()
Example #2
0
def refresh_brick_polls(org_id=None):
    start = time.time()
    r = get_redis_connection()

    key = 'refresh_brick_polls'
    lock_timeout = 3600

    if org_id:
        key = 'refresh_brick_polls:%d' % org_id
        lock_timeout = 600

    if not r.get(key):
        with r.lock(key, timeout=lock_timeout):
            active_orgs = Org.objects.filter(is_active=True)
            if org_id:
                active_orgs = Org.objects.filter(pk=org_id)

            for org in active_orgs:
                fetch_brick_polls_results(org)

            print "Task: Update_brick_polls took %ss" % (time.time() - start)
Example #3
0
def refresh_brick_polls(org_id=None):
    start = time.time()
    r = get_redis_connection()

    key = 'refresh_brick_polls'
    lock_timeout = 3600

    if org_id:
        key = 'refresh_brick_polls:%d' % org_id
        lock_timeout = 600

    if not r.get(key):
        with r.lock(key, timeout=lock_timeout):
            active_orgs = Org.objects.filter(is_active=True)
            if org_id:
                active_orgs = Org.objects.filter(pk=org_id)

            for org in active_orgs:
                fetch_brick_polls_results(org)


            print "Task: Update_brick_polls took %ss" % (time.time() - start)