mosquito / aio-pika

AMQP 0.9 client designed for asyncio and humans.
https://aio-pika.readthedocs.org/
Apache License 2.0
1.23k stars 187 forks source link

Question about fail_fast attribute #319

Open Lygoria opened 4 years ago

Lygoria commented 4 years ago

Hello!

First of all, thanks for the good job with this library! I have a question about the fail_fast attribute (https://github.com/mosquito/aio-pika/blob/master/aio_pika/robust_connection.py#L44). I want to start a RobustConnection that won't fail if the RabbitMQ is down (as https://github.com/mosquito/aio-pika/issues/202). The workaround works well but I wondered if I could use the fail_fast attribute instead :

connection = RobustConnection(RABBITMQ_URL, loop=loop, fail_fast="False")
await connection.connect()

I'm not sure there would be no consequences.

If so, would it be possible to make the exc_info configurable likewise ? https://github.com/mosquito/aio-pika/blob/master/aio_pika/robust_connection.py#L143

mosquito commented 4 years ago

First of all, use a boolean value for fail_fast = argument. That's means when the argument fail_fast = True driver just raises the original exception after the first connection attempt.

Lygoria commented 4 years ago

I tried to use a boolean value but it fails:

2020-05-15 06:46:43,783 asyncio      ERROR    Task exception was never retrieved
future: <Task finished name='Task-1' coro=<main() done, defined at client.py:164> exception=AttributeError("'bool' object has no attribute 'lower'")>
Traceback (most recent call last):
  File "client.py", line 51, in __init__
    connection = RobustConnection(RABBITMQ_URL, loop=loop, fail_fast=False)
  File "/home/vagrant/env/lib/python3.8/site-packages/aio_pika/robust_connection.py", line 39, in __init__
    super().__init__(url=url, loop=loop, **kwargs)
  File "/home/vagrant/env/lib/python3.8/site-packages/aio_pika/connection.py", line 53, in __init__
    self.kwargs = self._parse_kwargs(kwargs or self.url.query)
  File "/home/vagrant/env/lib/python3.8/site-packages/aio_pika/connection.py", line 46, in _parse_kwargs
    result[key] = parser(kwargs.get(key, default))
  File "/home/vagrant/env/lib/python3.8/site-packages/aiormq/connection.py", line 47, in parse_bool
    return v == "1" or v.lower() in ("true", "yes", "y", "enable", "on")
AttributeError: 'bool' object has no attribute 'lower'
themanifold commented 3 years ago

First of all, use a boolean value for fail_fast = argument.

Not true, as the parse_bool() function, given here, only accepts strings: https://github.com/mosquito/aiormq/blob/19d9372b504ce6d40ea4b1004bf62e398fe848a1/aiormq/connection.py#L85

Passing in "False" does work.