Skip to content

Commit

Permalink
fix: added retry case ConnectionError
Browse files Browse the repository at this point in the history
  • Loading branch information
caiquilipe committed Feb 28, 2024
1 parent 973055d commit d43d473
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion broadcaster/_backends/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from .._base import Event
from .base import BroadcastBackend
import asyncio


class RedisBackend(BroadcastBackend):
Expand Down Expand Up @@ -40,7 +41,12 @@ async def unsubscribe(self, channel: str) -> None:
await self._sub_conn.unsubscribe(channel)

async def publish(self, channel: str, message: Any) -> None:
await self._pub_conn.execute_command("PUBLISH", channel, message)
try:
await self._pub_conn.execute_command("PUBLISH", channel, message)
except redis.ConnectionError:
await asyncio.sleep(1)
self._pub_conn = redis.Redis(**self.kwargs).pubsub()
await self.publish(channel, message)

async def next_published(self) -> Event:
message = None
Expand Down

0 comments on commit d43d473

Please sign in to comment.