定义 Checker 接口(resolve/execute/serialize)和 CheckerRegistry 注册中心,消除 engine/config-loader/store 中硬编码类型分支。 按 checker 类型分子包(runner/http/、runner/command/),提取 共享 expect 到 runner/shared/。超时控制通过引擎注入 AbortSignal。 CheckFailure.phase 从联合类型改为 string。配置校验下沉到各 Checker.resolve() 内部。 新增 checker-runner-abstraction spec,更新 DEVELOPMENT.md。
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { loadConfig } from "./checker/config-loader";
|
|
import { ProbeStore } from "./checker/store";
|
|
import { ProbeEngine } from "./checker/engine";
|
|
import { startServer } from "./server";
|
|
import { readRuntimeConfig } from "./config";
|
|
import { registerCheckers } from "./checker/runner";
|
|
|
|
async function main() {
|
|
registerCheckers();
|
|
|
|
const { configPath } = readRuntimeConfig();
|
|
const config = await loadConfig(configPath);
|
|
|
|
const store = new ProbeStore(`${config.dataDir}/probe.db`);
|
|
store.syncTargets(config.targets);
|
|
|
|
const engine = new ProbeEngine(store, config.targets, config.maxConcurrentChecks);
|
|
engine.start();
|
|
|
|
const shutdown = () => {
|
|
engine.stop();
|
|
store.close();
|
|
process.exit(0);
|
|
};
|
|
process.on("SIGINT", shutdown);
|
|
process.on("SIGTERM", shutdown);
|
|
|
|
startServer({
|
|
config: { host: config.host, port: config.port },
|
|
mode: "development",
|
|
store,
|
|
});
|
|
}
|
|
|
|
void main().catch((error) => {
|
|
console.error("启动失败:", error instanceof Error ? error.message : error);
|
|
process.exit(1);
|
|
});
|