diff --git a/main.py b/main.py index 3b8ca73..aea1f07 100644 --- a/main.py +++ b/main.py @@ -390,18 +390,30 @@ class TelegramClient: if not NOTIFY_ON_WEEKENDS and msk_now().weekday() >= 5: log_info(f"[notify] Выходной день, отправка пропущена chat_id={chat_id}") return - try: - async with httpx.AsyncClient(timeout=20) as client: - response = await client.post( - f"{self.base_url}/sendMessage", - json={"chat_id": chat_id, "text": text}, + 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: + async with httpx.AsyncClient(timeout=45) as client: + response = await client.post( + f"{self.base_url}/sendMessage", + json={"chat_id": chat_id, "text": text}, + ) + response.raise_for_status() + log_info(f"[notify] Сообщение отправлено chat_id={chat_id} attempt={attempt_idx}") + return + except Exception as exc: + last_exc = exc + log_warn( + f"[notify] Ошибка отправки chat_id={chat_id} attempt={attempt_idx}/{len(delays)}: " + f"{type(exc).__name__}" ) - response.raise_for_status() - log_info(f"[notify] Сообщение отправлено chat_id={chat_id}") - except Exception as exc: - # Не роняем обработку webhook, если Telegram API временно недоступен - # или указан неверный токен/чат. - log_error("telegram send_message", exc) + # Не роняем обработку webhook, если Telegram API временно недоступен + # или указан неверный токен/чат. + if last_exc is not None: + log_error("telegram send_message", last_exc) class GiteaClient: