修復 too many connection 問題
This commit is contained in:
39
lib/app-initializer.ts
Normal file
39
lib/app-initializer.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
// =====================================================
|
||||
// 應用程式初始化器
|
||||
// =====================================================
|
||||
|
||||
import { dbShutdownManager } from './database-shutdown-manager';
|
||||
import { startConnectionMonitoring } from './database-middleware';
|
||||
import { smartPool } from './smart-connection-pool';
|
||||
|
||||
// 應用程式初始化
|
||||
export function initializeApp() {
|
||||
console.log('🚀 正在初始化應用程式...');
|
||||
|
||||
try {
|
||||
// 初始化資料庫關閉管理器
|
||||
console.log('📋 初始化資料庫關閉管理器...');
|
||||
const shutdownStatus = dbShutdownManager.getShutdownStatus();
|
||||
console.log('✅ 資料庫關閉管理器已初始化:', shutdownStatus);
|
||||
|
||||
// 啟動資料庫連線監控
|
||||
console.log('📊 啟動資料庫連線監控...');
|
||||
startConnectionMonitoring();
|
||||
|
||||
// 初始化智能連線池
|
||||
console.log('🧠 初始化智能連線池...');
|
||||
const poolStats = smartPool.getConnectionStats();
|
||||
console.log('✅ 智能連線池已初始化:', poolStats);
|
||||
|
||||
console.log('✅ 應用程式初始化完成');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 應用程式初始化失敗:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 在模組載入時自動初始化
|
||||
if (typeof window === 'undefined') {
|
||||
// 只在伺服器端執行
|
||||
initializeApp();
|
||||
}
|
Reference in New Issue
Block a user