arreglelo plix
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 1m5s

This commit is contained in:
2025-11-22 01:00:30 -06:00
parent 47c42cbcf3
commit 2500cb1181

View File

@@ -63,13 +63,14 @@ export async function query<T = any>(
text: string, text: string,
params?: any[] params?: any[]
): Promise<pg.QueryResult<T>> { ): Promise<pg.QueryResult<T>> {
const pool = getPool()
const start = Date.now() const start = Date.now()
const maxRetries = 2 const maxRetries = 2
for (let attempt = 0; attempt <= maxRetries; attempt++) { for (let attempt = 0; attempt <= maxRetries; attempt++) {
const currentPool = getPool()
try { try {
const result = await pool.query<T>(text, params) const result = await currentPool.query<T>(text, params)
const duration = Date.now() - start const duration = Date.now() - start
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
@@ -82,14 +83,14 @@ export async function query<T = any>(
const isConnError = ['ECONNREFUSED', 'ECONNRESET', '57P01'].includes(error?.code) const isConnError = ['ECONNREFUSED', 'ECONNRESET', '57P01'].includes(error?.code)
const shouldRetry = attempt < maxRetries && (isAuthError || isConnError) const shouldRetry = attempt < maxRetries && (isAuthError || isConnError)
console.error('Error ejecutando query:', { text, params, error: error?.message, code: error?.code, attempt }) console.error('Error ejecutando query:', { text, params, error: error?.message || error, code: error?.code, attempt })
if (shouldRetry) { if (shouldRetry) {
// Pequeño backoff y reintento // Pequeño backoff y reintento
await new Promise((res) => setTimeout(res, 500 * (attempt + 1))) await new Promise((res) => setTimeout(res, 500 * (attempt + 1)))
// Resetear pool en auth/conn error por si la contraseña/estado cambia en caliente // Resetear pool en auth/conn error por si la contraseña/estado cambia en caliente
try { try {
await pool.end() await currentPool.end()
} catch (_) {} } catch (_) {}
pool = null pool = null
continue continue