-
Notifications
You must be signed in to change notification settings - Fork 6
/
retry.py
28 lines (23 loc) · 829 Bytes
/
retry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from loguru import logger
from telegram.error import TimedOut
class Retry:
def __init__(self, retry_count, function, function_kwargs):
self.function_kwargs = function_kwargs
self.function = function
self.retry_count = retry_count
def retry(self):
raise NotImplementedError()
class TelegramTimedOutRetry(Retry):
def retry(self):
try:
return self.function(**self.function_kwargs)
except TimedOut as e:
if self.retry_count > 0:
logger.warning("Got timeout. Retrying.")
self.retry_count -= 1
return self.retry()
else:
logger.error(
"Raising 'TimedOut' exception, because maximum number of reties reached."
)
raise e