feat: 接入mysql数据库

This commit is contained in:
2026-09-04 17:01:12 +08:00
parent 38310f7b1c
commit 86a0d64182
22 changed files with 765 additions and 146 deletions

View File

@@ -5,17 +5,18 @@ from apscheduler.schedulers.background import BackgroundScheduler
from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware
from config.database import get_db
from routers import routers
from service import agent_service
scheduler = BackgroundScheduler()
def tip_job_task():
def article_job_task():
"""定时执行的任务"""
try:
print(f"今日资讯定时任务执行: {datetime.now()}")
agent_service.query_tip_agent()
agent_service.query_article_agent(get_db())
except Exception as e:
print(f"今日资讯定时任务异常: {e}")
@@ -23,12 +24,12 @@ def recipe_job_task():
"""定时执行的任务"""
try:
print(f"今日菜谱定时任务执行: {datetime.now()}")
agent_service.query_recipe_agent()
agent_service.query_recipe_agent(get_db())
except Exception as e:
print(f"今日菜谱定时任务异常: {e}")
scheduler.add_job(tip_job_task, trigger="cron", hour=2, minute=0, second=0, id="daily_gen_tips", replace_existing=True)
scheduler.add_job(article_job_task, trigger="cron", hour=2, minute=0, second=0, id="daily_gen_articles", replace_existing=True)
scheduler.add_job(recipe_job_task, trigger="cron", hour=3, minute=0, second=0, id="daily_gen_recipes", replace_existing=True)
@asynccontextmanager