feat: modo diff para /watch — notifica solo si hay novedades reales
Build & Deploy ResearchOwl / build-and-push (push) Successful in 7s

This commit is contained in:
ChemaVX
2026-05-05 07:43:41 +00:00
parent f4e167f3b6
commit 53cf7a04a8
3 changed files with 142 additions and 6 deletions
+42 -6
View File
@@ -73,7 +73,8 @@ async def send_chunked(message: Message, text: str, parse_mode=None):
async def run_scheduled_research(bot, chat_id: int, topic: str,
session_id: int, db: ResearchDB,
progress_message=None):
progress_message=None,
silent_completion: bool = False):
if progress_message is not None:
reporter = ProgressReporter(progress_message)
else:
@@ -106,9 +107,14 @@ async def run_scheduled_research(bot, chat_id: int, topic: str,
await processor.process_session(session_id, topic, proc_progress)
chunk_count = await db.get_chunks_count(session_id)
await reporter.done(
f"✅ Listo — `{scraped}` fuentes · `{chunk_count}` chunks · usa /generate <tipo>"
)
if silent_completion:
await reporter.done(
f"🔍 Investigación completada — analizando novedades…"
)
else:
await reporter.done(
f"✅ Listo — `{scraped}` fuentes · `{chunk_count}` chunks · usa /generate <tipo>"
)
else:
await reporter.done(
f"⚠️ Ollama no disponible — `{scraped}` fuentes scraped.\n"
@@ -726,11 +732,41 @@ async def _scheduler_loop(app: Application):
_active_sessions[chat_id] = session_id
await db.update_watch_run(watch["id"])
async def _task(c=chat_id, t=topic, s=session_id):
async def _task(c=chat_id, t=topic, s=session_id, w_id=watch["id"]):
inner_db_conn = await get_db()
inner_db = ResearchDB(inner_db_conn)
try:
await run_scheduled_research(app.bot, c, t, s, inner_db)
await run_scheduled_research(app.bot, c, t, s, inner_db,
silent_completion=True)
prev_session = await inner_db.get_previous_session(c, t, s)
new_urls = await inner_db.get_session_urls(s)
old_urls = await inner_db.get_session_urls(prev_session["id"]) \
if prev_session else set()
new_chunks = await inner_db.get_top_chunks(s, limit=30)
try:
from src.generator.generator import generate_diff_summary
summary = await generate_diff_summary(
t, new_urls, old_urls, new_chunks, s, inner_db
)
except Exception as e:
logger.warning("Diff summary failed", error=str(e))
summary = (
f"📊 *Actualización disponible — {t}*\n\n"
f"Usa /generate report para ver el análisis completo."
)
if summary:
await app.bot.send_message(
c, summary, parse_mode=ParseMode.MARKDOWN
)
else:
await app.bot.send_message(
c,
f"🔄 *{t}* — sin novedades significativas esta vez.",
parse_mode=ParseMode.MARKDOWN
)
finally:
await inner_db_conn.close()