-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (33 loc) · 1.02 KB
/
index.js
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
34
35
36
37
38
39
40
import app from "./src/Application";
import { timeout } from "@modules/utils";
import colors from 'colors';
import { initLog } from "@modules/logger";
// Время ожидания остановки процееса (в миллисекундах)
const EXIT_MAX_WAIT = 10000; // 10 secs
let APPLICATION_ALREADY_STOPPING = false;
// Обработка остановки сервера
process.on('SIGINT', async () => {
try {
if (APPLICATION_ALREADY_STOPPING)
return;
APPLICATION_ALREADY_STOPPING = true;
console.warn(colors.bgRed(`Received SIGINT signal! Application try to stop.`));
await Promise.race([
app.stop(),
timeout(EXIT_MAX_WAIT),
]);
} catch(e) {
console.error(`Application can't stop correct: ${e}`);
process.exit(1);
}
process.exit(0);
});
try {
initLog();
(async () => {
await app.init();
})();
} catch(e) {
console.error(`Application can't start corrent: ${e}`);
process.exit(1);
}