Skip to content

Commit c5ce3cf

Browse files
authored
Send with retry for redis.rpush (#92)
1 parent b74572c commit c5ce3cf

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

libmozevent/utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
import hglib
1414
import structlog
1515
from redis import asyncio as aioredis
16+
from redis.asyncio.retry import Retry
17+
from redis.backoff import ExponentialBackoff
18+
from redis.exceptions import ConnectionError
19+
from redis.exceptions import ExecAbortError
20+
from redis.exceptions import PubSubError
21+
from redis.exceptions import RedisError
22+
from redis.exceptions import ResponseError
23+
from redis.exceptions import TimeoutError
24+
from redis.exceptions import WatchError
1625

1726
log = structlog.get_logger(__name__)
1827

@@ -175,16 +184,33 @@ class AsyncRedis(object):
175184
@staticmethod
176185
async def connect():
177186
if AsyncRedis.redis.get(None) is None:
187+
retry_on_error = [
188+
ConnectionError,
189+
ExecAbortError,
190+
PubSubError,
191+
RedisError,
192+
ResponseError,
193+
TimeoutError,
194+
WatchError,
195+
]
196+
197+
RETRIES = 5
178198
AsyncRedis.redis.set(
179199
await aioredis.from_url(
180200
os.environ["REDIS_TLS_URL"],
181201
decode_responses=False,
182202
ssl_cert_reqs=None,
203+
health_check_interval=30,
204+
retry_on_error=retry_on_error,
205+
retry=Retry(ExponentialBackoff(cap=7, base=1), RETRIES),
183206
)
184207
if os.getenv("REDIS_TLS_URL", None) is not None
185208
else await aioredis.from_url(
186209
os.environ["REDIS_URL"],
187210
decode_responses=False,
211+
health_check_interval=30,
212+
retry_on_error=retry_on_error,
213+
retry=Retry(ExponentialBackoff(cap=7, base=1), RETRIES),
188214
)
189215
)
190216
return AsyncRedis.redis.get()

0 commit comments

Comments
 (0)