fix(scheduler): quiet cold-start noise gates
All checks were successful
CD Pipeline / deploy (push) Successful in 1m29s
All checks were successful
CD Pipeline / deploy (push) Successful in 1m29s
This commit is contained in:
41
scheduler.py
41
scheduler.py
@@ -60,6 +60,31 @@ def _save_stats(task_name, data):
|
||||
logging.error(f"[Scheduler] [Stats] ❌ 無法儲存排程統計 | Task: {task_name} | Error: {e}")
|
||||
|
||||
|
||||
WHITEPAGE_MARKER_GROUPS = [
|
||||
{
|
||||
"label": "導航佈局",
|
||||
"patterns": ("navbar", "momo-sidebar", "momo-topbar", "momo-layout", "login-card"),
|
||||
},
|
||||
{
|
||||
"label": "系統識別",
|
||||
"patterns": ("MOMO 價格監控系統", "EwoooC", "WOOO TECH", "商品看板", "價格監控"),
|
||||
},
|
||||
{
|
||||
"label": "內容容器",
|
||||
"patterns": ("card", "login-card", "momo-card", "container"),
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def _missing_whitepage_markers(content):
|
||||
"""Return marker groups missing from a non-blank momo page."""
|
||||
missing = []
|
||||
for group in WHITEPAGE_MARKER_GROUPS:
|
||||
if not any(pattern in content for pattern in group["patterns"]):
|
||||
missing.append(group["label"])
|
||||
return missing
|
||||
|
||||
|
||||
@contextmanager
|
||||
def managed_scraper_resources(window_size='1920,5000', debug=False, timeout=45, max_retries=2):
|
||||
"""
|
||||
@@ -1660,20 +1685,12 @@ def run_whitepage_check():
|
||||
|
||||
# 4. 檢查關鍵元素是否存在
|
||||
content = response.text
|
||||
required_elements = [
|
||||
'navbar', # 導航列
|
||||
'MOMO 價格監控系統', # 系統標題
|
||||
'card' # Bootstrap 卡片元素
|
||||
]
|
||||
|
||||
missing_elements = []
|
||||
for element in required_elements:
|
||||
if element not in content:
|
||||
missing_elements.append(element)
|
||||
|
||||
if missing_elements:
|
||||
error_msg = f"缺少關鍵元素:{', '.join(missing_elements)}"
|
||||
missing_markers = _missing_whitepage_markers(content)
|
||||
if missing_markers:
|
||||
error_msg = f"缺少關鍵元素:{', '.join(missing_markers)}"
|
||||
logging.error(f"[Whitepage] [Check] ❌ {error_msg}")
|
||||
logging.debug(f"[Whitepage] [Check] 📄 頁面內容片段: {content[:500]}...")
|
||||
NotificationManager().send_whitepage_alert(target_url, error_msg)
|
||||
_save_stats('whitepage_check', {"status": "Failed", "error": error_msg})
|
||||
return
|
||||
|
||||
@@ -30,7 +30,7 @@ from typing import Dict, List, Any, Optional
|
||||
from sqlalchemy import text
|
||||
from services.logger_manager import SystemLogger
|
||||
from services.elephant_alpha_orchestrator import elephant_orchestrator, StrategicDecision
|
||||
from database.manager import get_session
|
||||
from database.manager import get_db_manager, get_session
|
||||
|
||||
logger = SystemLogger("ElephantAlphaEngine").get_logger()
|
||||
|
||||
@@ -648,6 +648,7 @@ class ElephantAlphaAutonomousEngine:
|
||||
"generate_strategic_analysis",
|
||||
"generate_market_analysis",
|
||||
"generate_pricing_strategy",
|
||||
"generate_resource_optimization_strategy",
|
||||
"weekly_strategy",
|
||||
"meta_analysis",
|
||||
"strategic_analysis",
|
||||
@@ -685,7 +686,10 @@ class ElephantAlphaAutonomousEngine:
|
||||
# ---- Sub-services ----
|
||||
async def _hermes_analyze(self) -> Any:
|
||||
from services.hermes_analyst_service import HermesAnalystService
|
||||
return await self._run_with_timeout(HermesAnalystService().run, timeout=SSH_COMMAND_TIMEOUT)
|
||||
return await self._run_with_timeout(
|
||||
HermesAnalystService(engine=get_db_manager().engine).run,
|
||||
timeout=SSH_COMMAND_TIMEOUT,
|
||||
)
|
||||
|
||||
async def _fetch_hermes_threats_summary(self, top_n: int = 5) -> Optional[List[str]]:
|
||||
"""A' 軌:HITL escalation 前 pre-fetch Hermes 具體威脅清單,
|
||||
|
||||
@@ -63,6 +63,19 @@ def test_execute_step_routes_price_adjustment_to_human_review(monkeypatch):
|
||||
assert calls[0]["parameters"]["recommended_price"] == 1280
|
||||
|
||||
|
||||
def test_execute_step_skips_legacy_openclaw_resource_strategy():
|
||||
from services.elephant_alpha_autonomous_engine import ElephantAlphaAutonomousEngine
|
||||
|
||||
engine = ElephantAlphaAutonomousEngine()
|
||||
|
||||
result = asyncio.run(engine._execute_step({
|
||||
"agent": "openclaw",
|
||||
"action": "generate_resource_optimization_strategy",
|
||||
}))
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_autoheal_derives_python_exception_from_traceback():
|
||||
from services.auto_heal_service import AutoHealService
|
||||
|
||||
|
||||
22
tests/test_scheduler_whitepage_markers.py
Normal file
22
tests/test_scheduler_whitepage_markers.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from scheduler import _missing_whitepage_markers
|
||||
|
||||
|
||||
def test_whitepage_markers_accept_current_ewoooc_shell():
|
||||
html = """
|
||||
<html>
|
||||
<body>
|
||||
<aside class="momo-sidebar"></aside>
|
||||
<main class="momo-layout">
|
||||
<section class="momo-card">EwoooC 商品看板</section>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
assert _missing_whitepage_markers(html) == []
|
||||
|
||||
|
||||
def test_whitepage_markers_keep_blank_page_failing():
|
||||
html = "<html><body><main></main></body></html>"
|
||||
|
||||
assert _missing_whitepage_markers(html) == ["導航佈局", "系統識別", "內容容器"]
|
||||
Reference in New Issue
Block a user