fix: 使用 ?? 替代 || 运算符确保默认值正确设置
将逻辑或(||)运算符替换为空值合并(??)运算符,确保当配置值为0时不会被错误地替换为默认值。同时更新了相关日志信息以显示当前设置的maxErrorCount值。
This commit is contained in:
parent
211d677d00
commit
029d97236b
2 changed files with 5 additions and 4 deletions
|
|
@ -21,8 +21,9 @@ export class ProviderPoolManager {
|
||||||
this.globalConfig = options.globalConfig || {}; // 存储全局配置
|
this.globalConfig = options.globalConfig || {}; // 存储全局配置
|
||||||
this.providerStatus = {}; // Tracks health and usage for each provider instance
|
this.providerStatus = {}; // Tracks health and usage for each provider instance
|
||||||
this.roundRobinIndex = {}; // Tracks the current index for round-robin selection for each provider type
|
this.roundRobinIndex = {}; // Tracks the current index for round-robin selection for each provider type
|
||||||
this.maxErrorCount = options.maxErrorCount || 3; // Default to 3 errors before marking unhealthy
|
// 使用 ?? 运算符确保 0 也能被正确设置,而不是被 || 替换为默认值
|
||||||
this.healthCheckInterval = options.healthCheckInterval || 10 * 60 * 1000; // Default to 10 minutes
|
this.maxErrorCount = options.maxErrorCount ?? 3; // Default to 3 errors before marking unhealthy
|
||||||
|
this.healthCheckInterval = options.healthCheckInterval ?? 10 * 60 * 1000; // Default to 10 minutes
|
||||||
|
|
||||||
// 日志级别控制
|
// 日志级别控制
|
||||||
this.logLevel = options.logLevel || 'info'; // 'debug', 'info', 'warn', 'error'
|
this.logLevel = options.logLevel || 'info'; // 'debug', 'info', 'warn', 'error'
|
||||||
|
|
@ -87,7 +88,7 @@ export class ProviderPoolManager {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this._log('info', 'Initialized provider statuses: ok');
|
this._log('info', `Initialized provider statuses: ok (maxErrorCount: ${this.maxErrorCount})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ export async function initApiService(config) {
|
||||||
if (config.providerPools && Object.keys(config.providerPools).length > 0) {
|
if (config.providerPools && Object.keys(config.providerPools).length > 0) {
|
||||||
providerPoolManager = new ProviderPoolManager(config.providerPools, {
|
providerPoolManager = new ProviderPoolManager(config.providerPools, {
|
||||||
globalConfig: config,
|
globalConfig: config,
|
||||||
maxErrorCount: config.MAX_ERROR_COUNT || 3
|
maxErrorCount: config.MAX_ERROR_COUNT ?? 3
|
||||||
});
|
});
|
||||||
console.log('[Initialization] ProviderPoolManager initialized with configured pools.');
|
console.log('[Initialization] ProviderPoolManager initialized with configured pools.');
|
||||||
// 健康检查将在服务器完全启动后执行
|
// 健康检查将在服务器完全启动后执行
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue