Skip to content

Commit

Permalink
Retry set_webhook up to three times, reduce timeout to 5s again (#8716)
Browse files Browse the repository at this point in the history
  • Loading branch information
azogue authored and fabaff committed Jul 30, 2017
1 parent 05330ac commit cee49f3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions homeassistant/components/telegram_bot/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""
import asyncio
import datetime as dt
from functools import partial
from ipaddress import ip_network
import logging

Expand Down Expand Up @@ -70,9 +69,18 @@ def async_setup_platform(hass, config):
_LOGGER.error("Invalid telegram webhook %s must be https", handler_url)
return False

def _try_to_set_webhook():
retry_num = 0
while retry_num < 3:
try:
return bot.setWebhook(handler_url, timeout=5)
except telegram.error.TimedOut:
retry_num += 1
_LOGGER.warning("Timeout trying to set webhook (retry #%d)",
retry_num)

if current_status and current_status['url'] != handler_url:
result = yield from hass.async_add_job(
partial(bot.setWebhook, handler_url, timeout=10))
result = yield from hass.async_add_job(_try_to_set_webhook)
if result:
_LOGGER.info("Set new telegram webhook %s", handler_url)
else:
Expand Down

0 comments on commit cee49f3

Please sign in to comment.