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

34
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
try: delays = (0, 2, 5)
async with httpx.AsyncClient(timeout=20) as client: last_exc: Exception | None = None
response = await client.post( for attempt_idx, delay_s in enumerate(delays, start=1):
f"{self.base_url}/sendMessage", if delay_s > 0:
json={"chat_id": chat_id, "text": text}, 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() # Не роняем обработку webhook, если Telegram API временно недоступен
log_info(f"[notify] Сообщение отправлено chat_id={chat_id}") # или указан неверный токен/чат.
except Exception as exc: if last_exc is not None:
# Не роняем обработку webhook, если Telegram API временно недоступен log_error("telegram send_message", last_exc)
# или указан неверный токен/чат.
log_error("telegram send_message", exc)
class GiteaClient: class GiteaClient: