Merge pull request #5 from djw4/copilot/fix-runtime-error-starting-app
This commit is contained in:
commit
c76969fe8b
@ -2,8 +2,9 @@
|
||||
|
||||
import logging
|
||||
import sys
|
||||
from datetime import time
|
||||
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from telegram.ext import ContextTypes
|
||||
|
||||
from steward.bot.telegram import build_application, send_proposal
|
||||
from steward.config import get_settings
|
||||
@ -19,16 +20,14 @@ logging.basicConfig(
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def _run_scheduled_analysis(
|
||||
generator: ProposalGenerator,
|
||||
app, # type: ignore[type-arg]
|
||||
user_ids: list[int],
|
||||
) -> None:
|
||||
async def _run_scheduled_analysis(context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
"""Scheduled job: run analysis and push proposal via Telegram."""
|
||||
logger.info("Running scheduled analysis")
|
||||
generator: ProposalGenerator = context.bot_data["generator"]
|
||||
user_ids: list[int] = context.bot_data["user_ids"]
|
||||
proposal = await generator.run()
|
||||
if proposal:
|
||||
await send_proposal(app, proposal, user_ids)
|
||||
await send_proposal(context.application, proposal, user_ids)
|
||||
else:
|
||||
logger.info("No proposal generated (generator returned None)")
|
||||
|
||||
@ -60,16 +59,16 @@ def main() -> None:
|
||||
|
||||
app = build_application(settings, llm, thread_store, tool_client)
|
||||
generator = ProposalGenerator(settings, llm)
|
||||
app.bot_data["generator"] = generator
|
||||
app.bot_data["user_ids"] = settings.telegram_allowed_user_ids
|
||||
|
||||
scheduler = AsyncIOScheduler()
|
||||
scheduler.add_job(
|
||||
_run_scheduled_analysis,
|
||||
"cron",
|
||||
hour=settings.analysis_cron_hour,
|
||||
minute=settings.analysis_cron_minute,
|
||||
args=[generator, app, settings.telegram_allowed_user_ids],
|
||||
)
|
||||
scheduler.start()
|
||||
if app.job_queue is not None:
|
||||
app.job_queue.run_daily(
|
||||
_run_scheduled_analysis,
|
||||
time=time(hour=settings.analysis_cron_hour, minute=settings.analysis_cron_minute),
|
||||
)
|
||||
else:
|
||||
logger.warning("JobQueue not available – scheduled analysis disabled")
|
||||
|
||||
logger.info(
|
||||
"Steward starting: model=%s analysis_url=%s tools=%s",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user