Added log message when connection is established in polling process

This commit is contained in:
Alex Root Junior 2022-10-01 23:18:29 +03:00
parent 2e69100e1b
commit 4dbf69cd18
No known key found for this signature in database
GPG key ID: 074C1D455EBEA4AC

View file

@ -193,10 +193,12 @@ class Dispatcher(Router):
# Request timeout can be lower than session timeout and that's OK.
# To prevent false-positive TimeoutError we should wait longer than polling timeout
kwargs["request_timeout"] = int(bot.session.timeout + polling_timeout)
failed = False
while True:
try:
updates = await bot(get_updates, **kwargs)
except Exception as e:
failed = True
# In cases when Telegram Bot API was inaccessible don't need to stop polling
# process because some developers can't make auto-restarting of the script
loggers.dispatcher.error("Failed to fetch updates - %s: %s", type(e).__name__, e)
@ -212,7 +214,14 @@ class Dispatcher(Router):
# In case when network connection was fixed let's reset the backoff
# to initial value and then process updates
backoff.reset()
if failed:
loggers.dispatcher.info(
"Connection established (tryings = %d, bot id = %d)",
backoff.counter,
bot.id,
)
backoff.reset()
failed = False
for update in updates:
yield update