AIClient-2-API/healthcheck.js
hex2077 bdcb4320f4 feat: 新增提供商账号池模式支持
实现账号池功能,支持为所有提供商配置多个账号,提供轮询、故障转移和配置降级能力
修改适配器和服务处理逻辑以支持账号池管理
添加 ProviderPoolManager 类管理账号池健康状态和选择策略
更新文档说明账号池配置和使用方法
2025-08-29 17:00:18 +08:00

46 lines
No EOL
1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Docker健康检查脚本
* 用于检查API服务器是否正常运行
*/
import http from 'http';
// 从环境变量获取主机和端口,如果没有设置则使用默认值
const HOST = process.env.HOST || 'localhost';
const PORT = process.env.SERVER_PORT || 3000;
// 发送HTTP请求到健康检查端点
const options = {
hostname: HOST,
port: PORT,
path: '/health',
method: 'GET',
timeout: 2000 // 2秒超时
};
const req = http.request(options, (res) => {
// 如果状态码是200表示服务健康
if (res.statusCode === 200) {
console.log('Health check passed');
process.exit(0);
} else {
console.log(`Health check failed with status code: ${res.statusCode}`);
process.exit(1);
}
});
// 处理请求错误
req.on('error', (e) => {
console.error(`Health check failed: ${e.message}`);
process.exit(1);
});
// 设置超时处理
req.on('timeout', () => {
console.error('Health check timed out');
req.destroy();
process.exit(1);
});
// 结束请求
req.end();