From 4dbf69cd18e83382e55ed6bf83a8c1d59c213bfa Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sat, 1 Oct 2022 23:18:29 +0300 Subject: [PATCH] Added log message when connection is established in polling process --- aiogram/dispatcher/dispatcher.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/aiogram/dispatcher/dispatcher.py b/aiogram/dispatcher/dispatcher.py index 6fb29059..4aa60672 100644 --- a/aiogram/dispatcher/dispatcher.py +++ b/aiogram/dispatcher/dispatcher.py @@ -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