Skip to content

Commit 1911191

Browse files
committed
temp: add error logging to telegram in cron job
1 parent 23a3678 commit 1911191

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

cron.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import asyncio
22
import os
33
import logging
4+
import traceback
45
from telegram.ext import Application
6+
from tg_ids import ROZEN_CHATID
57
from bot_logic import _update_groups, felizdia, actualizarRiver
68

79
def main():
@@ -14,9 +16,28 @@ def main():
1416
application = Application.builder().token(os.environ["TELEGRAM_BOT_TOKEN"]).build()
1517

1618
async def run_update():
17-
await _update_groups(application)
18-
await felizdia(application)
19-
await actualizarRiver(application)
19+
try:
20+
await application.bot.send_message(chat_id=ROZEN_CHATID, text="Arrancando cron job...")
21+
except Exception:
22+
pass
23+
24+
try:
25+
await felizdia(application)
26+
except Exception as e:
27+
error_msg = f"Error en felizdia:\n{traceback.format_exc()}"
28+
await application.bot.send_message(chat_id=ROZEN_CHATID, text=error_msg[:4000])
29+
30+
try:
31+
await actualizarRiver(application)
32+
except Exception as e:
33+
error_msg = f"Error en actualizarRiver:\n{traceback.format_exc()}"
34+
await application.bot.send_message(chat_id=ROZEN_CHATID, text=error_msg[:4000])
35+
36+
try:
37+
await _update_groups(application)
38+
except Exception as e:
39+
error_msg = f"Error en update_groups:\n{traceback.format_exc()}"
40+
await application.bot.send_message(chat_id=ROZEN_CHATID, text=error_msg[:4000])
2041

2142
asyncio.run(run_update())
2243

0 commit comments

Comments
 (0)