| self.__polling_task = asyncio.create_task( | ||
| self._network_loop_retry( | ||
| network_retry_loop( | ||
| is_running=lambda: self.running, |
as long as the delay between them is large enough to eliminate intermittent connectivity problems as the source of potential problems
So far I have implemented the initial retry-interval to 0 seconds for Application.initialize
| interval=0, |
but I see that the bootstrapping within Updater uses an initial interval of 1 second - I can use that for Application as well:
| bootstrap_interval: float = 1, |
Note that the retry-loop retries immediately on timeout errors. On other errors, the interval is increased step by step up to 30 seconds:
| try: | |
| if not await do_action(): | |
| break | |
| except RetryAfter as exc: | |
| slack_time = 0.5 | |
| _LOGGER.info( | |
| "%s %s. Adding %s seconds to the specified time.", log_prefix, exc, slack_time | |
| ) | |
| cur_interval = slack_time + exc.retry_after | |
| except TimedOut as toe: | |
| _LOGGER.debug("%s Timed out: %s. Retrying immediately.", log_prefix, toe) | |
| # If failure is due to timeout, we should retry asap. | |
| cur_interval = 0 | |
| except InvalidToken: | |
| _LOGGER.exception("%s Invalid token. Aborting retry loop.", log_prefix) | |
| raise | |
| except TelegramError as telegram_exc: | |
| if on_err_cb: | |
| on_err_cb(telegram_exc) | |
| if max_retries < 0 or retries < max_retries: | |
| _LOGGER.debug( | |
| "%s Failed run number %s of %s. Retrying.", log_prefix, retries, max_retries | |
| ) | |
| else: | |
| _LOGGER.exception( | |
| "%s Failed run number %s of %s. Aborting.", log_prefix, retries, max_retries | |
| ) | |
| raise | |
| # increase waiting times on subsequent errors up to 30secs | |
| cur_interval = 1 if cur_interval == 0 else min(30, 1.5 * cur_interval) |
Specifying the retry-interval is currently not exposed to the user in the Updater.start_* methods and for starters that would seem like a bit of overkill, TBH.
@septatrix would this + (customizable) finite number of retries be enough for you?
โ 2 Tests Failed:
| Tests completed | Failed | Passed | Skipped |
|---|---|---|---|
| 6531 | 2 | 6529 | 746 |
Stack Traces | 7.35s run timetests.test_bot.TestBotWithRequest::test_send_close_date_default_tz[Europe/Berlin-ZoneInfo]self = <tests.test_bot.TestBotWithRequest object at 0x000001CE6EFE70D0> tz_bot = PytestExtBot[token=690091347:AAFLmR5pAB5Ycpe_mOh7zM4JFBOh0z3T0To] super_group_id = '-1001279600026' async def test_send_close_date_default_tz(self, tz_bot, super_group_id): question = "Is this a test?" answers = ["Yes", "No", "Maybe"] reply_markup = InlineKeyboardMarkup.from_button( InlineKeyboardButton(text="text", callback_data="data") ) aware_close_date = dtm.datetime.now(tz=tz_bot.defaults.tzinfo) + dtm.timedelta(seconds=5) close_date = aware_close_date.replace(tzinfo=None) msg = await tz_bot.send_poll( # The timezone returned from this is always converted to UTC chat_id=super_group_id, question=question, options=answers, close_date=close_date, read_timeout=60, ) msg.poll._unfreeze() # Sometimes there can be a few seconds delay, so don't let the test fail due to that- > msg.poll.close_date = msg.poll.close_date.astimezone(aware_close_date.tzinfo) E AttributeError: 'NoneType' object has no attribute 'astimezone' tests\test_bot.py:2843: AttributeError
Stack Traces | 7.37s run timetests.test_bot.TestBotWithRequest::test_send_close_date_default_tz[Asia/Singapore-timezone]self = <tests.test_bot.TestBotWithRequest object at 0x00000223F0A048D0> tz_bot = PytestExtBot[token=690091347:AAFLmR5pAB5Ycpe_mOh7zM4JFBOh0z3T0To] super_group_id = '-1001279600026' async def test_send_close_date_default_tz(self, tz_bot, super_group_id): question = "Is this a test?" answers = ["Yes", "No", "Maybe"] reply_markup = InlineKeyboardMarkup.from_button( InlineKeyboardButton(text="text", callback_data="data") ) aware_close_date = dtm.datetime.now(tz=tz_bot.defaults.tzinfo) + dtm.timedelta(seconds=5) close_date = aware_close_date.replace(tzinfo=None) msg = await tz_bot.send_poll( # The timezone returned from this is always converted to UTC chat_id=super_group_id, question=question, options=answers, close_date=close_date, read_timeout=60, ) msg.poll._unfreeze() # Sometimes there can be a few seconds delay, so don't let the test fail due to that- > msg.poll.close_date = msg.poll.close_date.astimezone(aware_close_date.tzinfo) E AttributeError: 'NoneType' object has no attribute 'astimezone' tests\test_bot.py:2843: AttributeError
To view more test analytics, go to the Test Analytics Dashboard
๐ Got 3 mins? Take this short survey to help us improve Test Analytics.