mirror of
https://github.com/directus/directus.git
synced 2026-01-27 11:38:04 -05:00
Co-authored-by: Nitwel <mail@nitwel.de> Co-authored-by: Jan Arends <jaads@users.noreply.github.com> Co-authored-by: Brainslug <br41nslug@users.noreply.github.com> Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com> Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
30 lines
759 B
TypeScript
30 lines
759 B
TypeScript
import { Knex } from 'knex';
|
|
import axios from 'axios';
|
|
import { sleep } from './sleep';
|
|
|
|
export async function awaitDatabaseConnection(database: Knex, checkSQL: string): Promise<void | null> {
|
|
for (let attempt = 0; attempt <= 30; attempt++) {
|
|
try {
|
|
await database.raw(checkSQL);
|
|
return null; // success
|
|
} catch (error) {
|
|
await sleep(5000);
|
|
continue;
|
|
}
|
|
}
|
|
throw new Error(`Couldn't connect to DB`);
|
|
}
|
|
|
|
export async function awaitDirectusConnection(port: number): Promise<void | null> {
|
|
for (let attempt = 0; attempt <= 100; attempt++) {
|
|
try {
|
|
await axios.get(`http://127.0.0.1:${port}/server/ping`);
|
|
return null; // success
|
|
} catch {
|
|
await sleep(5000);
|
|
continue;
|
|
}
|
|
}
|
|
throw new Error(`Couldn't connect to Directus`);
|
|
}
|