mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-21 22:56:38 +01:00
WIP retry failed requests
This commit is contained in:
parent
8e5cb58f46
commit
8abdfdd5e7
1 changed files with 8 additions and 4 deletions
|
@ -115,8 +115,7 @@ class Bot(TelegramObject):
|
|||
|
||||
return decorator
|
||||
|
||||
@staticmethod
|
||||
def _post_message(url, data, msg_cls=Message, expect_list=False, timeout=None, **kwargs):
|
||||
def _post_message(self, url, data, msg_cls=Message, expect_list=False, timeout=None, **kwargs):
|
||||
reply_to_message_id = kwargs.get('reply_to_message_id')
|
||||
if reply_to_message_id:
|
||||
data['reply_to_message_id'] = reply_to_message_id
|
||||
|
@ -131,7 +130,7 @@ class Bot(TelegramObject):
|
|||
reply_markup = reply_markup.to_json()
|
||||
data['reply_markup'] = reply_markup
|
||||
|
||||
result = request.post(url, data, timeout=timeout)
|
||||
result = self._request_wrapper(request.post, url, data, timeout=timeout)
|
||||
|
||||
if isinstance(result, int):
|
||||
# int covers both boolean & integer results
|
||||
|
@ -142,6 +141,11 @@ class Bot(TelegramObject):
|
|||
|
||||
return msg_cls.de_json(result)
|
||||
|
||||
def _request_wrapper(self, method, url, *args, **kwargs):
|
||||
# classes inheriting from Bot, can wrap this method in order to perform retries
|
||||
# this is intended to be used only with request.post() & request.get()
|
||||
return method(url, *args, **kwargs)
|
||||
|
||||
@log
|
||||
def getMe(self, **kwargs):
|
||||
"""A simple method for testing your bot's auth token.
|
||||
|
@ -158,7 +162,7 @@ class Bot(TelegramObject):
|
|||
|
||||
url = '{0}/getMe'.format(self.base_url)
|
||||
|
||||
result = request.get(url)
|
||||
result = self._request_wrapper(request.get, url)
|
||||
|
||||
self._bot = User.de_json(result)
|
||||
|
||||
|
|
Loading…
Reference in a new issue