inital
This commit is contained in:
31
backend/app/scheduler.py
Normal file
31
backend/app/scheduler.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import logging
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from apscheduler.triggers.cron import CronTrigger
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
scheduler = AsyncIOScheduler(timezone="Asia/Shanghai")
|
||||
|
||||
|
||||
async def daily_pipeline_job():
|
||||
from .database import AsyncSessionLocal
|
||||
from .ai.processor import run_daily_pipeline
|
||||
async with AsyncSessionLocal() as db:
|
||||
try:
|
||||
await run_daily_pipeline(db)
|
||||
except Exception as e:
|
||||
logger.error(f"Daily pipeline failed: {e}", exc_info=True)
|
||||
|
||||
|
||||
def start_scheduler():
|
||||
scheduler.add_job(daily_pipeline_job, CronTrigger(hour=6, minute=0), id="daily_pipeline", replace_existing=True)
|
||||
scheduler.start()
|
||||
logger.info("Scheduler started — daily pipeline runs at 06:00 Asia/Shanghai")
|
||||
|
||||
|
||||
def shutdown_scheduler():
|
||||
scheduler.shutdown(wait=False)
|
||||
|
||||
|
||||
async def trigger_now():
|
||||
"""Manually trigger the pipeline (called from admin API)."""
|
||||
await daily_pipeline_job()
|
||||
Reference in New Issue
Block a user