Skip to content

Commit

Permalink
Merge pull request #64 from khizunov/anton/try_except_listen
Browse files Browse the repository at this point in the history
fix #65: avoid worker crash in case connection is broken
  • Loading branch information
s3rius authored Sep 28, 2024
2 parents 254fae4 + b5e9328 commit e30ed08
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions taskiq_redis/redis_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ async def listen(self) -> AsyncGenerator[bytes, None]:
:yields: broker messages.
"""
redis_brpop_data_position = 1
async with Redis(connection_pool=self.connection_pool) as redis_conn:
while True:
yield (await redis_conn.brpop(self.queue_name))[
redis_brpop_data_position
]
while True:
try:
async with Redis(connection_pool=self.connection_pool) as redis_conn:
yield (await redis_conn.brpop(self.queue_name))[
redis_brpop_data_position
]
except ConnectionError as exc:
logger.warning("Redis connection error: %s", exc)
continue

0 comments on commit e30ed08

Please sign in to comment.