mirror of
https://github.com/directus/directus.git
synced 2026-01-31 06:27:58 -05:00
* Declare return types on functions And a very few other type related minor fixes * Minor syntax fixes * Remove unnecessary escape chars in regexes * Remove unnecessary awaits * Replace deprecated req.connection with req.socket * Replace deprecated upload with uploadOne * Remove unnecessary eslint-disable-next-line comments * Comment empty functions / catch or finally clauses * Fix irregular whitespaces * Add missing returns (null) * Remove unreachable code * A few logical fixes * Remove / Handle non-null assertions which are certainly unnecessary (e.g. in tests)
41 lines
937 B
TypeScript
41 lines
937 B
TypeScript
import { Knex } from 'knex';
|
|
import axios from 'axios';
|
|
|
|
export async function awaitDatabaseConnection(
|
|
database: Knex,
|
|
checkSQL: string,
|
|
currentAttempt = 0
|
|
): Promise<void | null> {
|
|
try {
|
|
await database.raw(checkSQL);
|
|
} catch {
|
|
if (currentAttempt === 10) {
|
|
throw new Error(`Couldn't connect to DB`);
|
|
}
|
|
|
|
return new Promise((resolve) => {
|
|
setTimeout(async () => {
|
|
await awaitDatabaseConnection(database, checkSQL, currentAttempt + 1);
|
|
resolve(null);
|
|
}, 5000);
|
|
});
|
|
}
|
|
}
|
|
|
|
export async function awaitDirectusConnection(port = 6100, currentAttempt = 0): Promise<void | null> {
|
|
try {
|
|
await axios.get(`http://localhost:${port}/server/ping`);
|
|
} catch {
|
|
if (currentAttempt === 10) {
|
|
throw new Error(`Couldn't connect to Directus`);
|
|
}
|
|
|
|
return new Promise((resolve) => {
|
|
setTimeout(async () => {
|
|
await awaitDirectusConnection(port, currentAttempt + 1);
|
|
resolve(null);
|
|
}, 5000);
|
|
});
|
|
}
|
|
}
|