feat(voice): M47 后端启动后探活 emotionTTS,未起则异步拉起一键启动脚本
主人 2026-10-24:「tts启动脚本在这 ...\一键启动.bat,以后启动后端可以顺便检测 一下如果TTS没起就顺带启一下」。本片只做「启动时顺带探一下」,**默认关**(主人 早前说过「开机自启先不急 后面做」),未开开关时连探活都不发。 - 新包 internal/runtime/voice/ttslaunch:探 http://127.0.0.1:9880(毫秒级超时), 已在跑什么都不做;没起则异步起脚本(cmd.exe /c 传参,不拼命令行字符串) - 防重复:in-flight 单飞 + 一次尝试后的冷却(失败也算一次,重启风暴不会变成重试风暴) - 失败只 WARN:探活超时/脚本不存在/起进程失败都只记带 source 的日志, 组合根那条路径**没有 error 通道** - 配置走面板文件 $DATA_DIR/config/voice-tts-launch.json(零新 .env 键) - 接线在 cmd/cyrene 的网关 Listen 之后,整段在后台 goroutine 里,不占启动时长 (用例以「挂载耗时 < 150ms 而探活超时 800ms」证明) - 不新开端点、不加帧族;不碰 gateway 包
This commit is contained in:
1 parent
af61b8ccfe
commit
6906d274fc
13 files changed
+1354
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package ttslaunch
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// probeBodyLimit 是探活响应的最大读取量:探活只关心"有没有人应答",回应体一律丢弃,
|
||||
// 但也要有界(别被一个话痨服务的无限流拖住)。
|
||||
const probeBodyLimit = 4 << 10
|
||||
|
||||
// httpProbe 用一次 HTTP GET 回答「这个端口上已经有人在应答吗」。
|
||||
//
|
||||
// 判定口径(刻意宽松):**任何** HTTP 回应都算"在跑",只有传输层错误(连不上 /
|
||||
// 超时 / 连接被拒)才算"没起"。理由是这个服务的根路径回什么状态码并不稳定
|
||||
// (404/405/200 都可能),而"端口有人说话"已经足以证明不该再拉第二个实例 ——
|
||||
// 误判成"没起"的代价是去起一个抢同一个端口的进程,代价明显更大。
|
||||
//
|
||||
// `Proxy: nil` 是必须的:探的是回环地址,走环境里的 HTTP_PROXY 只会问到代理上,
|
||||
// 得到"有人在跑"的假结论。
|
||||
func httpProbe(url string, timeout time.Duration) probeFunc {
|
||||
client := &http.Client{
|
||||
Timeout: timeout,
|
||||
Transport: &http.Transport{
|
||||
Proxy: nil,
|
||||
DisableKeepAlives: true,
|
||||
},
|
||||
}
|
||||
return func(ctx context.Context) error {
|
||||
reqCtx, cancel := context.WithTimeout(ctx, timeout)
|
||||
defer cancel()
|
||||
req, err := http.NewRequestWithContext(reqCtx, http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ttslaunch: build probe request: %w", err)
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ttslaunch: probe %s: %w", url, err)
|
||||
}
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
_, _ = io.Copy(io.Discard, io.LimitReader(resp.Body, probeBodyLimit))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// discardLogger 是没注入日志器时的兜底(绝不 nil 解引用)。
|
||||
func discardLogger() *slog.Logger {
|
||||
return slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
}
|
||||
Reference in new issue
Block a user