修复手动搜索调度时区
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
from typing import Literal, Optional
|
from typing import Literal, Optional
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, Request
|
from fastapi import APIRouter, Depends, Request
|
||||||
@@ -61,7 +61,7 @@ def trigger_daily_run(
|
|||||||
scheduler.add_job(
|
scheduler.add_job(
|
||||||
run_scheduled_job,
|
run_scheduled_job,
|
||||||
trigger="date",
|
trigger="date",
|
||||||
run_date=datetime.now(),
|
run_date=datetime.now(scheduler.timezone) + timedelta(seconds=1),
|
||||||
args=[settings],
|
args=[settings],
|
||||||
id=f"manual-intelligence-{datetime.now().timestamp()}",
|
id=f"manual-intelligence-{datetime.now().timestamp()}",
|
||||||
max_instances=1,
|
max_instances=1,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
@@ -78,6 +79,48 @@ def test_manual_agent_run_endpoint_starts_background_job(monkeypatch) -> None:
|
|||||||
assert started == ["test"]
|
assert started == ["test"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_manual_agent_run_endpoint_uses_scheduler_when_available(monkeypatch) -> None:
|
||||||
|
# 生产环境手动搜索投递到常驻调度器,避免HTTP请求承载长时间联网搜索。
|
||||||
|
monkeypatch.setenv("SIGNALSCOUT_ENV", "test")
|
||||||
|
get_settings.cache_clear()
|
||||||
|
engine = create_engine(
|
||||||
|
"sqlite:///:memory:",
|
||||||
|
connect_args={"check_same_thread": False},
|
||||||
|
poolclass=StaticPool,
|
||||||
|
future=True,
|
||||||
|
)
|
||||||
|
TestingSessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False, future=True)
|
||||||
|
Base.metadata.create_all(engine)
|
||||||
|
scheduled = []
|
||||||
|
|
||||||
|
class FakeScheduler:
|
||||||
|
running = True
|
||||||
|
timezone = ZoneInfo("Asia/Shanghai")
|
||||||
|
|
||||||
|
def add_job(self, *args, **kwargs):
|
||||||
|
scheduled.append(kwargs)
|
||||||
|
|
||||||
|
def override_get_db():
|
||||||
|
# 调度器路径同样使用内存库检查运行中状态。
|
||||||
|
db = TestingSessionLocal()
|
||||||
|
try:
|
||||||
|
yield db
|
||||||
|
finally:
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
app = create_app()
|
||||||
|
app.state.scheduler = FakeScheduler()
|
||||||
|
app.dependency_overrides[get_db] = override_get_db
|
||||||
|
with TestClient(app) as client:
|
||||||
|
response = client.post("/agent/runs/daily")
|
||||||
|
get_settings.cache_clear()
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json()["status"] == "started"
|
||||||
|
assert scheduled[0]["trigger"] == "date"
|
||||||
|
assert scheduled[0]["run_date"].tzinfo is not None
|
||||||
|
|
||||||
|
|
||||||
def test_dashboard_returns_news_and_github_signals_separately(monkeypatch) -> None:
|
def test_dashboard_returns_news_and_github_signals_separately(monkeypatch) -> None:
|
||||||
# 仪表盘接口直接返回分组后的业务数据,前端不再用标题或来源名自行猜测分类。
|
# 仪表盘接口直接返回分组后的业务数据,前端不再用标题或来源名自行猜测分类。
|
||||||
monkeypatch.setenv("SIGNALSCOUT_ENV", "test")
|
monkeypatch.setenv("SIGNALSCOUT_ENV", "test")
|
||||||
|
|||||||
Reference in New Issue
Block a user