修正資料庫未關閉問題
This commit is contained in:
@@ -6,10 +6,11 @@ import { NextRequest, NextResponse } from 'next/server';
|
||||
import { db } from './database';
|
||||
import { dbMonitor } from './database-monitor';
|
||||
import { dbShutdownManager } from './database-shutdown-manager';
|
||||
import { connectionMonitor } from './connection-monitor';
|
||||
|
||||
// 連線池狀態追蹤
|
||||
let connectionCount = 0;
|
||||
const maxConnections = 3; // 與資料庫配置保持一致
|
||||
const maxConnections = 20; // 與資料庫配置保持一致
|
||||
|
||||
export function withDatabaseConnection<T extends any[]>(
|
||||
handler: (...args: T) => Promise<NextResponse>
|
||||
@@ -87,11 +88,12 @@ export async function checkConnectionHealth(): Promise<{
|
||||
usagePercentage: number;
|
||||
}> {
|
||||
try {
|
||||
const stats = dbMonitor.getConnectionStats();
|
||||
// 使用連線監控器獲取詳細統計
|
||||
const stats = await connectionMonitor.getConnectionStats();
|
||||
|
||||
return {
|
||||
isHealthy: stats.usagePercentage < 80,
|
||||
connectionCount: stats.currentConnections,
|
||||
isHealthy: stats.isHealthy,
|
||||
connectionCount: stats.activeConnections,
|
||||
maxConnections: stats.maxConnections,
|
||||
usagePercentage: stats.usagePercentage
|
||||
};
|
||||
|
Reference in New Issue
Block a user