-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstartup.ts
33 lines (28 loc) · 920 Bytes
/
startup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { AppServer } from './config/server';
import { logger } from './config/logger';
import { unhandledRejection } from './src/errors/unhandledRejection';
import { uncaughtException } from './src/errors/uncaughtException';
uncaughtException();
unhandledRejection();
const server = new AppServer();
/**
* I did this because of docker it will fail because the server has not started yet
* so we have to wait and call it every time it fails.
* I don't like this solution but for now this is a work around
*/
async function runner(): Promise<void> {
try {
await server.startDB();
} catch (error) {
const promiseTimer: NodeJS.Timer = await new Promise((res) => {
const timer = setTimeout(() => {
res(timer);
}, 10000);
});
clearTimeout(promiseTimer);
runner();
logger.error(error, 'SERVER ERROR:');
logger.info('still awaiting for database...');
}
}
runner();