@open-xchange/fastify-sdk 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/database/mariadb.js +20 -2
- package/package.json +12 -6
package/lib/database/mariadb.js
CHANGED
|
@@ -8,7 +8,9 @@ const defaults = {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function createMariaDBPool (options = {}) {
|
|
11
|
-
const
|
|
11
|
+
const config = { ...defaults, ...options }
|
|
12
|
+
const pool = mariadb.createPool(config)
|
|
13
|
+
pool._connConfig = config
|
|
12
14
|
pool.on('connection', (connection) => {
|
|
13
15
|
connection.query('SET SESSION time_zone="+00:00"')
|
|
14
16
|
})
|
|
@@ -48,15 +50,31 @@ export function createMariaDBPoolFromEnv ({ prefix = 'SQL', names } = {}) {
|
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
export async function mariadbReadyCheck (pool, { retries = 12, delay = 10_000, logger } = {}) {
|
|
53
|
+
// Pools created via createMariaDBPool() have _connConfig attached.
|
|
54
|
+
// Use createConnection() directly for these because the pool swallows
|
|
55
|
+
// connection errors and waits the full acquireTimeout (10s) before
|
|
56
|
+
// returning a generic ER_GET_CONNECTION_TIMEOUT. Direct connections
|
|
57
|
+
// fail immediately with the real error (ECONNREFUSED etc.), making
|
|
58
|
+
// retries fast. Falls back to pool.query() for plain mock pools.
|
|
59
|
+
const useDirectConnect = Boolean(pool._connConfig)
|
|
60
|
+
const config = useDirectConnect ? { ...pool._connConfig, connectTimeout: defaults.connectTimeout } : null
|
|
51
61
|
for (let i = 1; i <= retries; i++) {
|
|
62
|
+
let conn
|
|
52
63
|
try {
|
|
53
|
-
|
|
64
|
+
if (useDirectConnect) {
|
|
65
|
+
conn = await mariadb.createConnection(config)
|
|
66
|
+
await conn.query('SELECT 1')
|
|
67
|
+
} else {
|
|
68
|
+
await pool.query('SELECT 1')
|
|
69
|
+
}
|
|
54
70
|
if (logger) logger.info('Database is ready')
|
|
55
71
|
return
|
|
56
72
|
} catch (err) {
|
|
57
73
|
if (logger) logger.warn(`Database not ready (attempt ${i}/${retries}): ${err.code} ${err.message}`)
|
|
58
74
|
if (i === retries) throw err
|
|
59
75
|
await new Promise(resolve => setTimeout(resolve, delay))
|
|
76
|
+
} finally {
|
|
77
|
+
if (conn) await conn.end().catch(() => {})
|
|
60
78
|
}
|
|
61
79
|
}
|
|
62
80
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-xchange/fastify-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Shared foundation package for OX App Suite Node.js services",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
"./redis": "./lib/redis/index.js",
|
|
14
14
|
"./testing": "./lib/testing/index.js"
|
|
15
15
|
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"lint": "eslint . --cache --fix",
|
|
18
|
+
"test": "vitest run",
|
|
19
|
+
"test:coverage": "vitest run --coverage"
|
|
20
|
+
},
|
|
16
21
|
"author": "Open-Xchange",
|
|
17
22
|
"license": "AGPL-3.0-or-later",
|
|
18
23
|
"dependencies": {
|
|
@@ -70,9 +75,10 @@
|
|
|
70
75
|
"engines": {
|
|
71
76
|
"node": ">=20"
|
|
72
77
|
},
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
"
|
|
76
|
-
|
|
78
|
+
"packageManager": "pnpm@10.27.0",
|
|
79
|
+
"pnpm": {
|
|
80
|
+
"onlyBuiltDependencies": [
|
|
81
|
+
"unrs-resolver"
|
|
82
|
+
]
|
|
77
83
|
}
|
|
78
|
-
}
|
|
84
|
+
}
|