42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import debugLog from "./logging/debug-log";
|
|
import mariaDBlocalQuery from "./mariadb-local-query";
|
|
import sleep from "./sleep";
|
|
|
|
let checkDbRetries = 0;
|
|
const MAX_CHECK_DB_RETRIES = 10;
|
|
const DEFAULT_SLEEP_TIME = 3000;
|
|
|
|
type Params = {
|
|
maxRetries?: number;
|
|
sleepTime?: number;
|
|
};
|
|
|
|
export default async function dockerTestDbConnection(params?: Params) {
|
|
const maxRetries = params?.maxRetries || MAX_CHECK_DB_RETRIES;
|
|
const sleepTime = params?.sleepTime || DEFAULT_SLEEP_TIME;
|
|
|
|
while (true) {
|
|
if (checkDbRetries > maxRetries) {
|
|
debugLog({
|
|
log: `Max Retries for checking Database. Exiting ...`,
|
|
addTime: true,
|
|
label: "MaxRetries",
|
|
});
|
|
process.exit(1);
|
|
}
|
|
|
|
const checkDb = mariaDBlocalQuery(`SHOW DATABASES`);
|
|
|
|
const isDbReady =
|
|
typeof checkDb == "string" &&
|
|
Boolean(checkDb.match(/\ninformation_schema\n/));
|
|
|
|
if (isDbReady) {
|
|
break;
|
|
} else {
|
|
checkDbRetries++;
|
|
await sleep(sleepTime);
|
|
}
|
|
}
|
|
}
|