@qrvey/health-checker
Version:
 
43 lines • 1.52 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PostgreSQLHealthChecker = void 0;
const requireEnv_1 = require("../../utils/requireEnv");
const pg_1 = require("pg");
const logger_1 = __importDefault(require("../../utils/logger"));
const PG_ENV_VAR = 'MULTIPLATFORM_PG_CONNECTION_STRING';
async function connectAndQuery(client) {
await client.connect();
await client.query('SELECT 1');
}
async function closeConnection(client) {
try {
await client.end();
}
catch (error) {
logger_1.default.warn('[PostgreSQLHealthChecker] Failed to close connection', error);
}
}
exports.PostgreSQLHealthChecker = {
dependency: 'database',
async check() {
const connectionString = (0, requireEnv_1.requireEnv)(PG_ENV_VAR);
const client = new pg_1.Client({ connectionString });
try {
await connectAndQuery(client);
if (process.env.NODE_ENV === 'test') {
logger_1.default.info('[PostgreSQLHealthChecker] check executed successfully');
}
}
catch (error) {
logger_1.default.error('[PostgreSQLHealthChecker] Failed to connect or query', error);
throw error;
}
finally {
await closeConnection(client);
}
},
};
//# sourceMappingURL=postgresqlHealthChecker.service.js.map