feat: JSON 配置、质量分与仪表盘,及设置与爬取流程
- 后端改为 config/app.json;pytest 使用 config/app.test.json 与 set_config_file,不再依赖环境变量;移除 pydantic-settings。 - 前端 API/WebSocket 由 config/webui.json 经 Vite define 注入。 - 代理分数按延迟与随机取用次数计算,新增 use_count 与 proxy_scoring;保存设置时同步调度器启停。 - 仪表盘双饼图(可用/待验证协议);设置页去掉调度器启停按钮并移动立即验证;爬取全部结束后自动提交全量验证。 - 删除 script/settings_maintain.py(此前已标记删除)。 Made-with: Cursor
This commit is contained in:
@@ -26,6 +26,7 @@ def format_proxy(proxy) -> dict:
|
||||
"response_time_ms": proxy.response_time_ms,
|
||||
"last_check": proxy.last_check.isoformat() if proxy.last_check else None,
|
||||
"validated": getattr(proxy, "validated", 0),
|
||||
"use_count": int(getattr(proxy, "use_count", 0) or 0),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ from app.core.plugin_system.registry import registry
|
||||
from app.repositories.proxy_repo import ProxyRepository
|
||||
from app.repositories.settings_repo import SettingsRepository, DEFAULT_SETTINGS
|
||||
from app.services.validator_service import ValidatorService
|
||||
from app.services.proxy_scoring import compute_proxy_quality_score
|
||||
from app.services.plugin_runner import PluginRunner
|
||||
from app.services.scheduler_service import SchedulerService
|
||||
from app.api.ws_manager import ConnectionManager
|
||||
@@ -63,12 +64,21 @@ async def lifespan(app: FastAPI):
|
||||
return
|
||||
if existing.validated == 0:
|
||||
if is_valid:
|
||||
lat_ms = (
|
||||
float(latency)
|
||||
if latency is not None and float(latency) > 0
|
||||
else None
|
||||
)
|
||||
uc = int(getattr(existing, "use_count", 0) or 0)
|
||||
q_score = compute_proxy_quality_score(
|
||||
lat_ms, uc, app_settings
|
||||
)
|
||||
await proxy_repo.insert_or_update(
|
||||
db,
|
||||
proxy.ip,
|
||||
proxy.port,
|
||||
proxy.protocol,
|
||||
score=app_settings.score_valid,
|
||||
score=q_score,
|
||||
)
|
||||
if latency:
|
||||
await proxy_repo.update_response_time(
|
||||
@@ -78,12 +88,21 @@ async def lifespan(app: FastAPI):
|
||||
await proxy_repo.delete(db, proxy.ip, proxy.port)
|
||||
else:
|
||||
if is_valid:
|
||||
lat_ms = (
|
||||
float(latency)
|
||||
if latency is not None and float(latency) > 0
|
||||
else None
|
||||
)
|
||||
uc = int(getattr(existing, "use_count", 0) or 0)
|
||||
q_score = compute_proxy_quality_score(
|
||||
lat_ms, uc, app_settings
|
||||
)
|
||||
await proxy_repo.insert_or_update(
|
||||
db,
|
||||
proxy.ip,
|
||||
proxy.port,
|
||||
proxy.protocol,
|
||||
score=app_settings.score_valid,
|
||||
score=q_score,
|
||||
)
|
||||
if latency:
|
||||
await proxy_repo.update_response_time(
|
||||
|
||||
@@ -4,7 +4,8 @@ from pydantic import BaseModel
|
||||
|
||||
from app.services.plugin_service import PluginService
|
||||
from app.services.plugin_runner import PluginRunner
|
||||
from app.core.execution import JobExecutor, CrawlJob
|
||||
from app.core.execution import JobExecutor, CrawlJob, ValidateAllJob
|
||||
from app.core.log import logger
|
||||
from app.core.exceptions import PluginNotFoundException
|
||||
from app.api.deps import get_plugin_service, get_plugin_runner, get_executor
|
||||
from app.api.common import success_response, format_plugin
|
||||
@@ -106,7 +107,7 @@ async def crawl_all(
|
||||
|
||||
|
||||
def _create_crawl_all_aggregator(job_ids, executor):
|
||||
"""创建一个简单的聚合 Job,查询所有子 Job 的状态汇总"""
|
||||
"""创建一个简单的聚合 Job,查询所有子 Job 的状态汇总;正常结束时自动提交一次全量验证"""
|
||||
from app.core.execution.job import Job
|
||||
import asyncio
|
||||
|
||||
@@ -177,6 +178,13 @@ def _create_crawl_all_aggregator(job_ids, executor):
|
||||
}
|
||||
if self.is_cancelled:
|
||||
result["cancelled"] = True
|
||||
else:
|
||||
v_job = ValidateAllJob(validator_pool=executor.worker_pool)
|
||||
result["validate_all_task_id"] = executor.submit_job(v_job)
|
||||
logger.info(
|
||||
"Crawl-all finished; submitted ValidateAllJob %s",
|
||||
result["validate_all_task_id"],
|
||||
)
|
||||
return result
|
||||
|
||||
return CrawlAllAggregator()
|
||||
|
||||
@@ -43,6 +43,18 @@ async def save_settings(
|
||||
scheduler.interval_minutes = new_interval
|
||||
logger.info(f"Scheduler interval updated to {new_interval} minutes")
|
||||
|
||||
want_run = bool(request.auto_validate)
|
||||
if want_run and not scheduler.running:
|
||||
try:
|
||||
await scheduler.start()
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to start scheduler after settings save: {e}")
|
||||
elif not want_run and scheduler.running:
|
||||
try:
|
||||
await scheduler.stop()
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to stop scheduler after settings save: {e}")
|
||||
|
||||
# 热更新 Worker 池大小
|
||||
if worker_pool and worker_pool.worker_count != request.default_concurrency:
|
||||
await worker_pool.resize(request.default_concurrency)
|
||||
|
||||
Reference in New Issue
Block a user