This commit is contained in:
Raykov-MS 2026-03-20 15:05:11 +03:00
parent 91338ca40f
commit 04cf58dd1f

18
main.py
View File

@ -390,18 +390,30 @@ class TelegramClient:
if not NOTIFY_ON_WEEKENDS and msk_now().weekday() >= 5: if not NOTIFY_ON_WEEKENDS and msk_now().weekday() >= 5:
log_info(f"[notify] Выходной день, отправка пропущена chat_id={chat_id}") log_info(f"[notify] Выходной день, отправка пропущена chat_id={chat_id}")
return return
delays = (0, 2, 5)
last_exc: Exception | None = None
for attempt_idx, delay_s in enumerate(delays, start=1):
if delay_s > 0:
await asyncio.sleep(delay_s)
try: try:
async with httpx.AsyncClient(timeout=20) as client: async with httpx.AsyncClient(timeout=45) as client:
response = await client.post( response = await client.post(
f"{self.base_url}/sendMessage", f"{self.base_url}/sendMessage",
json={"chat_id": chat_id, "text": text}, json={"chat_id": chat_id, "text": text},
) )
response.raise_for_status() response.raise_for_status()
log_info(f"[notify] Сообщение отправлено chat_id={chat_id}") log_info(f"[notify] Сообщение отправлено chat_id={chat_id} attempt={attempt_idx}")
return
except Exception as exc: except Exception as exc:
last_exc = exc
log_warn(
f"[notify] Ошибка отправки chat_id={chat_id} attempt={attempt_idx}/{len(delays)}: "
f"{type(exc).__name__}"
)
# Не роняем обработку webhook, если Telegram API временно недоступен # Не роняем обработку webhook, если Telegram API временно недоступен
# или указан неверный токен/чат. # или указан неверный токен/чат.
log_error("telegram send_message", exc) if last_exc is not None:
log_error("telegram send_message", last_exc)
class GiteaClient: class GiteaClient: