Esempio n. 1
0
    def _get_connection(self, index=None):
        if index is None:
            index = self._get_random_index()

        if not 0 <= index < self._ring_size:
            raise ValueError(
                'There are only {count} hosts, but you asked for connection {index}.'
                .format(
                    count=self._ring_size,
                    index=index,
                ))

        for i in range(self._sentinel_failover_retries + 1):
            try:
                return self._get_master_client_for(self._services[index])
            except redis.sentinel.MasterNotFoundError:
                self.reset_clients(
                )  # make sure we reach out to get master info again on next call
                if i == self._sentinel_failover_retries:
                    raise CannotGetConnectionError(
                        'Master not found; gave up reloading master info after failover.'
                    )
                self._get_counter(
                    'backend.sentinel.master_not_found_retry').increment()
                time.sleep((2**i + random.random()) / 4.0)
Esempio n. 2
0
    def test_cannot_get_connection_error_on_receive(self, mock_standard, mock_sentinel):
        core = RedisTransportCore(backend_type=REDIS_BACKEND_TYPE_STANDARD)

        mock_standard.return_value.get_connection.side_effect = CannotGetConnectionError('This is another error')

        with self.assertRaises(MessageReceiveError) as error_context:
            core.receive_message('your_queue')

        self.assertEquals('Cannot get connection: This is another error', error_context.exception.args[0])

        self.assertFalse(mock_sentinel.called)
        mock_standard.return_value.get_connection.assert_called_once_with('pysoa:your_queue')
Esempio n. 3
0
    def _get_connection(self, index):  # type: (int) -> redis.StrictRedis
        if not 0 <= index < self._ring_size:
            raise ValueError(
                'There are only {count} hosts, but you asked for connection {index}.'.format(
                    count=self._ring_size,
                    index=index,
                )
            )

        for i in range(self._sentinel_failover_retries + 1):
            try:
                return self._get_master_client_for(self._services[index])
            except redis.sentinel.MasterNotFoundError:
                self.reset_clients()  # make sure we reach out to get master info again on next call
                _logger.warning('Redis master not found, so resetting clients (failover?)')
                if i != self._sentinel_failover_retries:
                    self._get_counter('backend.sentinel.master_not_found_retry').increment()
                    time.sleep((2 ** i + random.random()) / 4.0)

        raise CannotGetConnectionError('Master not found; gave up reloading master info after failover.')