auto_agent/edge-agent/app/executors/tcp_probe_executor.py
2521690 ce299cbb18 feat: 增加 Agent 演示入口与 app_metadata 驱动验证链路
- 新增 app_metadata 模型、仓储与服务
- 将默认 edge 验证步骤改为由 app_metadata 驱动生成
- 新增 chat_session / chat_message 会话层模型与 chat service
- 新增 demo chat API,支持会话创建、消息发送、任务确认
- 新增最小 Web Demo 页面,形成聊天式演示入口
- 增强任务报告,补充 audit_summary 与更细粒度 task_metrics
- 增强 edge-agent 执行器:tcp_probe、日志时间范围过滤、进程指标与更灵活健康检查
- 更新 README 与当前进度总结,MVP 进度推进到约 94%
2026-04-09 14:10:13 +08:00

42 lines
1.3 KiB
Python

from __future__ import annotations
import socket
import time
from typing import Any
class TcpProbeExecutor:
def execute(self, params: dict[str, Any]) -> tuple[bool, str, dict[str, Any], dict[str, Any]]:
host = str(params.get("host", "127.0.0.1"))
port = int(params["port"])
timeout_ms = int(params.get("timeout_ms", 3000))
started_at = time.perf_counter()
try:
with socket.create_connection((host, port), timeout=timeout_ms / 1000.0):
latency_ms = max(int((time.perf_counter() - started_at) * 1000), 0)
return (
True,
"tcp probe succeeded",
{
"host": host,
"port": port,
"connected": True,
"latency_ms": latency_ms,
},
{},
)
except OSError as exc:
latency_ms = max(int((time.perf_counter() - started_at) * 1000), 0)
return (
False,
str(exc),
{
"host": host,
"port": port,
"connected": False,
"latency_ms": latency_ms,
},
{},
)