Revert "feat(boot-notification): 添加超时处理和日志记录以增强引导通知的持久性"

This reverts commit 8a537e80e3.
This commit is contained in:
2026-03-15 04:28:32 +08:00
parent 8a537e80e3
commit 8f3b2fd6e2
2 changed files with 43 additions and 73 deletions

View File

@@ -9,8 +9,6 @@ export const useDrizzle = () => {
if (!pgPoolInstance || !drizzleInstance) {
pgPoolInstance = new Pool({
connectionString: process.env.DATABASE_CONNECTION_STRING,
connectionTimeoutMillis: 3000,
idleTimeoutMillis: 10000,
})
drizzleInstance = drizzle({ client: pgPoolInstance, schema })
}

View File

@@ -8,29 +8,14 @@ import type {
} from '../types.ts'
const DEFAULT_HEARTBEAT_INTERVAL = 60
const BOOT_NOTIFICATION_DB_TIMEOUT_MS = 3000
function withTimeout<T>(promise: Promise<T>, timeoutMs: number, label: string) {
return Promise.race<T>([
promise,
new Promise<T>((_, reject) => {
setTimeout(() => reject(new Error(`${label} timed out after ${timeoutMs}ms`)), timeoutMs)
}),
])
}
export async function handleBootNotification(
payload: BootNotificationRequest,
ctx: OcppConnectionContext,
): Promise<BootNotificationResponse> {
const db = useDrizzle()
const currentTime = dayjs().toISOString()
console.log(`[OCPP] BootNotification ${ctx.chargePointIdentifier} received`)
try {
const [cp] = await withTimeout(
db
const [cp] = await db
.insert(chargePoint)
.values({
id: crypto.randomUUID(),
@@ -65,10 +50,7 @@ export async function handleBootNotification(
updatedAt: dayjs().toDate(),
},
})
.returning(),
BOOT_NOTIFICATION_DB_TIMEOUT_MS,
`BootNotification persistence for ${ctx.chargePointIdentifier}`,
)
.returning()
const status = cp.registrationStatus
ctx.isRegistered = status === 'Accepted'
@@ -76,18 +58,8 @@ export async function handleBootNotification(
console.log(`[OCPP] BootNotification ${ctx.chargePointIdentifier} status=${status}`)
return {
currentTime,
currentTime: dayjs().toISOString(),
interval: DEFAULT_HEARTBEAT_INTERVAL,
status,
}
} catch (error) {
ctx.isRegistered = false
console.error(`[OCPP] BootNotification ${ctx.chargePointIdentifier} persistence failed:`, error)
return {
currentTime,
interval: DEFAULT_HEARTBEAT_INTERVAL,
status: 'Pending',
}
}
}