- Notifications
You must be signed in to change notification settings - Fork5.7k
Add Bootstrapping Logic toApplication.run_*
#4673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
315a97f
6e64043
f933cfd
4d60f00
14008d3
575fdce
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -30,7 +30,8 @@ | ||||
from telegram._utils.logging import get_logger | ||||
from telegram._utils.repr import build_repr_with_selected_attrs | ||||
from telegram._utils.types import DVType, ODVInput | ||||
from telegram.error import TelegramError | ||||
from telegram.ext._utils.networkloop import network_retry_loop | ||||
try: | ||||
from telegram.ext._utils.webhookhandler import WebhookAppClass, WebhookServer | ||||
@@ -206,7 +207,7 @@ async def start_polling( | ||||
self, | ||||
poll_interval: float = 0.0, | ||||
timeout: int = 10, | ||||
bootstrap_retries: int =0, | ||||
read_timeout: ODVInput[float] = DEFAULT_NONE, | ||||
write_timeout: ODVInput[float] = DEFAULT_NONE, | ||||
connect_timeout: ODVInput[float] = DEFAULT_NONE, | ||||
@@ -225,12 +226,16 @@ async def start_polling( | ||||
Telegram in seconds. Default is ``0.0``. | ||||
timeout (:obj:`int`, optional): Passed to | ||||
:paramref:`telegram.Bot.get_updates.timeout`. Defaults to ``10`` seconds. | ||||
bootstrap_retries (:obj:`int`, optional): Whether the bootstrapping phase of | ||||
will retry on failures on the Telegram server. | ||||
* < 0 - retry indefinitely | ||||
* 0 - no retries (default) | ||||
* > 0 - retry up to X times | ||||
.. versionchanged:: NEXT.VERSION | ||||
The default value will be changed to from ``-1`` to ``0``. Indefinite retries | ||||
during bootstrapping are not recommended. | ||||
read_timeout (:obj:`float`, optional): Value to pass to | ||||
:paramref:`telegram.Bot.get_updates.read_timeout`. Defaults to | ||||
:attr:`~telegram.request.BaseRequest.DEFAULT_NONE`. | ||||
@@ -409,12 +414,14 @@ def default_error_callback(exc: TelegramError) -> None: | ||||
# updates from Telegram and inserts them in the update queue of the | ||||
# Application. | ||||
self.__polling_task = asyncio.create_task( | ||||
network_retry_loop( | ||||
is_running=lambda: self.running, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. why is that a lambda? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
this line expects a callable. If we simply pass whileis_running: then we have an infinite loop, b/c setting classHasRunning(Protocol):running:bool would sound like the next best thing to me at first glance | ||||
action_cb=polling_action_cb, | ||||
on_err_cb=error_callback or default_error_callback, | ||||
description="Polling Updates", | ||||
interval=poll_interval, | ||||
stop_event=self.__polling_task_stop_event, | ||||
max_retries=-1, | ||||
Bibo-Joshi marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||||
), | ||||
name="Updater:start_polling:polling_task", | ||||
) | ||||
@@ -507,8 +514,8 @@ async def start_webhook( | ||||
Telegram servers before actually starting to poll. Default is :obj:`False`. | ||||
.. versionadded :: 13.4 | ||||
bootstrap_retries (:obj:`int`, optional): Whether the bootstrapping phase of | ||||
will retry on failures on the Telegram server. | ||||
* < 0 - retry indefinitely | ||||
* 0 - no retries (default) | ||||
@@ -698,78 +705,6 @@ def _gen_webhook_url(protocol: str, listen: str, port: int, url_path: str) -> st | ||||
# say differently! | ||||
return f"{protocol}://{listen}:{port}{url_path}" | ||||
async def _bootstrap( | ||||
self, | ||||
max_retries: int, | ||||
@@ -786,7 +721,6 @@ async def _bootstrap( | ||||
updates if appropriate. If there are unsuccessful attempts, this will retry as specified by | ||||
:paramref:`max_retries`. | ||||
""" | ||||
async def bootstrap_del_webhook() -> bool: | ||||
_LOGGER.debug("Deleting webhook") | ||||
@@ -810,45 +744,30 @@ async def bootstrap_set_webhook() -> bool: | ||||
) | ||||
return False | ||||
# Dropping pending updates from TG can be efficiently done with the drop_pending_updates | ||||
# parameter of delete/start_webhook, even in the case of polling. Also, we want to make | ||||
# sure that no webhook is configured in case of polling, so we just always call | ||||
# delete_webhook for polling | ||||
if drop_pending_updates or not webhook_url: | ||||
awaitnetwork_retry_loop( | ||||
is_running=lambda: self.running, | ||||
action_cb=bootstrap_del_webhook, | ||||
description="Bootstrap delete Webhook", | ||||
interval=bootstrap_interval, | ||||
stop_event=None, | ||||
max_retries=max_retries, | ||||
) | ||||
# Restore/set webhook settings, if needed. Again, we don't know ahead if a webhook is set, | ||||
# so we set it anyhow. | ||||
if webhook_url: | ||||
awaitnetwork_retry_loop( | ||||
is_running=lambda: self.running, | ||||
action_cb=bootstrap_set_webhook, | ||||
description="Bootstrap Set Webhook", | ||||
interval=bootstrap_interval, | ||||
stop_event=None, | ||||
max_retries=max_retries, | ||||
) | ||||
async def stop(self) -> None: | ||||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.