@ejfdelgado/ejflab-back 1.29.0 → 1.30.1
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/package.json +1 -1
- package/srv/PostgresSrv.mjs +12 -2
package/package.json
CHANGED
package/srv/PostgresSrv.mjs
CHANGED
@@ -79,12 +79,14 @@ export class PostgresSrv {
|
|
79
79
|
const database = process.env.POSTGRES_DB || "nogales";
|
80
80
|
const user = process.env.POSTGRES_USER || "user";
|
81
81
|
const password = process.env.POSTGRES_PASSWORD || "pass";
|
82
|
+
const timeout = process.env.POSTGRES_TIMEOUT || "2000";
|
82
83
|
return {
|
83
84
|
host,
|
84
85
|
port,
|
85
86
|
database,
|
86
87
|
user,
|
87
88
|
password,
|
89
|
+
timeout,
|
88
90
|
};
|
89
91
|
}
|
90
92
|
|
@@ -139,17 +141,25 @@ export class PostgresSrv {
|
|
139
141
|
host: params.host,
|
140
142
|
port: params.port,
|
141
143
|
database: params.database,
|
144
|
+
connectionTimeoutMillis: parseInt(params.timeout),
|
142
145
|
});
|
143
146
|
}
|
144
147
|
|
145
|
-
static async
|
148
|
+
static async checkSelect1() {
|
146
149
|
if (PostgresSrv.pool == null) {
|
147
150
|
PostgresSrv.createPool();
|
148
151
|
}
|
149
152
|
try {
|
150
153
|
await PostgresSrv.pool.query('SELECT 1;');
|
154
|
+
return true;
|
151
155
|
} catch (err) {
|
152
|
-
|
156
|
+
return false;
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
static async getPool() {
|
161
|
+
const canSelect1 = await PostgresSrv.checkSelect1();
|
162
|
+
if (!canSelect1) {
|
153
163
|
PostgresSrv.createPool();
|
154
164
|
}
|
155
165
|
return PostgresSrv.pool;
|