コード例 #1
0
ファイル: __init__.py プロジェクト: sverrejoh/celery
    def _open_connection(self):
        """Retries connecting to the AMQP broker over time.

        See :func:`celery.utils.retry_over_time`.

        """

        def _connection_error_handler(exc, interval):
            """Callback handler for connection errors."""
            self.logger.error("AMQP Listener: Connection Error: %s. " % exc
                     + "Trying again in %d seconds..." % interval)

        def _establish_connection():
            """Establish a connection to the AMQP broker."""
            conn = DjangoBrokerConnection()
            connected = conn.connection # Connection is established lazily.
            return conn

        if not conf.AMQP_CONNECTION_RETRY:
            return _establish_connection()

        conn = retry_over_time(_establish_connection, (socket.error, IOError),
                               errback=_connection_error_handler,
                               max_retries=conf.AMQP_CONNECTION_MAX_RETRIES)
        self.logger.debug("CarrotListener: Connection Established.")
        return conn
コード例 #2
0
    def test_returns_retval_on_success(self):

        def _fun(x, y):
            return x * y

        ret = utils.retry_over_time(_fun, (socket.error, ), args=[16, 16],
                                    max_retries=3)

        self.assertEqual(ret, 256)
コード例 #3
0
ファイル: test_utils.py プロジェクト: jokar/minion
    def test_returns_retval_on_success(self):
        def _fun(x, y):
            return x * y

        ret = utils.retry_over_time(_fun, (socket.error, ),
                                    args=[16, 16],
                                    max_retries=3)

        self.assertEqual(ret, 256)
コード例 #4
0
    def test_retries_on_failure(self):

        iterations = [0]

        def _fun(x, y):
            iterations[0] += 1
            if iterations[0] == 3:
                return x * y
            raise socket.error("foozbaz")

        ret = utils.retry_over_time(_fun, (socket.error, ), args=[32, 32],
                                    max_retries=None)

        self.assertEqual(iterations[0], 3)
        self.assertEqual(ret, 1024)

        self.assertRaises(socket.error, utils.retry_over_time,
                        _fun, (socket.error, ), args=[32, 32], max_retries=1)
コード例 #5
0
ファイル: test_utils.py プロジェクト: jokar/minion
    def test_retries_on_failure(self):

        iterations = [0]

        def _fun(x, y):
            iterations[0] += 1
            if iterations[0] == 3:
                return x * y
            raise socket.error("foozbaz")

        ret = utils.retry_over_time(_fun, (socket.error, ),
                                    args=[32, 32],
                                    max_retries=None)

        self.assertEqual(iterations[0], 3)
        self.assertEqual(ret, 1024)

        self.assertRaises(socket.error,
                          utils.retry_over_time,
                          _fun, (socket.error, ),
                          args=[32, 32],
                          max_retries=1)