48 lines
2.3 KiB
JavaScript
48 lines
2.3 KiB
JavaScript
"use strict";
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.default = dockerTestDbConnection;
|
|
const debug_log_1 = __importDefault(require("./logging/debug-log"));
|
|
const mariadb_local_query_1 = __importDefault(require("./mariadb-local-query"));
|
|
const sleep_1 = __importDefault(require("./sleep"));
|
|
let checkDbRetries = 0;
|
|
const MAX_CHECK_DB_RETRIES = 10;
|
|
const DEFAULT_SLEEP_TIME = 3000;
|
|
function dockerTestDbConnection(params) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
const maxRetries = (params === null || params === void 0 ? void 0 : params.maxRetries) || MAX_CHECK_DB_RETRIES;
|
|
const sleepTime = (params === null || params === void 0 ? void 0 : params.sleepTime) || DEFAULT_SLEEP_TIME;
|
|
while (true) {
|
|
if (checkDbRetries > maxRetries) {
|
|
(0, debug_log_1.default)({
|
|
log: `Max Retries for checking Database. Exiting ...`,
|
|
addTime: true,
|
|
label: "MaxRetries",
|
|
});
|
|
process.exit(1);
|
|
}
|
|
const checkDb = (0, mariadb_local_query_1.default)(`SHOW DATABASES`);
|
|
const isDbReady = typeof checkDb == "string" &&
|
|
Boolean(checkDb.match(/\ninformation_schema\n/));
|
|
if (isDbReady) {
|
|
break;
|
|
}
|
|
else {
|
|
checkDbRetries++;
|
|
yield (0, sleep_1.default)(sleepTime);
|
|
}
|
|
}
|
|
});
|
|
}
|