From 853c425bb952df5a5c7fd5364b7a6b0a8ed0378d Mon Sep 17 00:00:00 2001 From: Flare Date: Sat, 28 Jun 2025 03:31:17 +0500 Subject: [PATCH] Add polling_interval parameter in Dispatcher --- aiogram/dispatcher/dispatcher.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/aiogram/dispatcher/dispatcher.py b/aiogram/dispatcher/dispatcher.py index 63fd33c2..6e261e49 100644 --- a/aiogram/dispatcher/dispatcher.py +++ b/aiogram/dispatcher/dispatcher.py @@ -195,6 +195,7 @@ class Dispatcher(Router): polling_timeout: int = 30, backoff_config: BackoffConfig = DEFAULT_BACKOFF_CONFIG, allowed_updates: Optional[List[str]] = None, + polling_interval: float = 0, ) -> AsyncGenerator[Update, None]: """ Endless updates reader with correctly handling any server-side or connection errors. @@ -246,6 +247,8 @@ class Dispatcher(Router): # as confirmed on the server and will no longer be returned. get_updates.offset = update.update_id + 1 + await asyncio.sleep(polling_interval) + async def _listen_update(self, update: Update, **kwargs: Any) -> Any: """ Main updates listener @@ -344,6 +347,7 @@ class Dispatcher(Router): backoff_config: BackoffConfig = DEFAULT_BACKOFF_CONFIG, allowed_updates: Optional[List[str]] = None, tasks_concurrency_limit: Optional[int] = None, + polling_interval: float = 0, **kwargs: Any, ) -> None: """ @@ -356,6 +360,7 @@ class Dispatcher(Router): :param allowed_updates: List of the update types you want your bot to receive :param tasks_concurrency_limit: Maximum number of concurrent updates to process (None = no limit), used only if handle_as_tasks is True + :param polling_interval: Time in seconds between requests for updates :param kwargs: :return: """ @@ -375,6 +380,7 @@ class Dispatcher(Router): polling_timeout=polling_timeout, backoff_config=backoff_config, allowed_updates=allowed_updates, + polling_interval=polling_interval, ): handle_update = self._process_update(bot=bot, update=update, **kwargs) if handle_as_tasks: @@ -503,6 +509,7 @@ class Dispatcher(Router): handle_signals: bool = True, close_bot_session: bool = True, tasks_concurrency_limit: Optional[int] = None, + polling_interval: float = 0, **kwargs: Any, ) -> None: """ @@ -518,6 +525,7 @@ class Dispatcher(Router): :param close_bot_session: close bot sessions on shutdown :param tasks_concurrency_limit: Maximum number of concurrent updates to process (None = no limit), used only if handle_as_tasks is True + :param polling_interval: Time in seconds between requests for updates :param kwargs: contextual data :return: """ @@ -574,6 +582,7 @@ class Dispatcher(Router): backoff_config=backoff_config, allowed_updates=allowed_updates, tasks_concurrency_limit=tasks_concurrency_limit, + polling_interval=polling_interval, **workflow_data, ) ) @@ -609,6 +618,7 @@ class Dispatcher(Router): handle_signals: bool = True, close_bot_session: bool = True, tasks_concurrency_limit: Optional[int] = None, + polling_interval: float = 0, **kwargs: Any, ) -> None: """ @@ -623,6 +633,7 @@ class Dispatcher(Router): :param close_bot_session: close bot sessions on shutdown :param tasks_concurrency_limit: Maximum number of concurrent updates to process (None = no limit), used only if handle_as_tasks is True + :param polling_interval: Time in seconds between requests for updates :param kwargs: contextual data :return: """ @@ -638,5 +649,6 @@ class Dispatcher(Router): handle_signals=handle_signals, close_bot_session=close_bot_session, tasks_concurrency_limit=tasks_concurrency_limit, + polling_interval=polling_interval ) )