-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
87 lines (62 loc) · 1.6 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const webServerUtil = require('./util/web-server.js');
const databaseUtil = require('./util/database.js');
const databaseConfig = require('./config/database.js');
const defaultThreadPoolSize = 4;
const oracledb = require('oracledb');
// Increase thread pool size by poolMax
process.env.UV_THREADPOOL_SIZE = databaseConfig.todoPool.poolMax + defaultThreadPoolSize;
async function startup() {
console.log('Starting application');
try {
console.log('Initializing database module');
await databaseUtil.initialize();
} catch (err) {
console.error(err);
process.exit(1); // Non-zero failure code
}
try {
console.log('Initializing web server module');
await webServerUtil.initialize();
} catch (err) {
console.error(err);
process.exit(1); // Non-zero failure code
}
}
startup();
async function shutdown(e) {
let err = e;
console.log('Shutting down application');
try {
console.log('Closing web server module');
await webServerUtil.close();
} catch (e) {
console.error(e);
err = err || e;
}
try {
console.log('Closing database module');
await databaseUtil.close();
} catch (e) {
console.error(e);
err = err || e;
}
console.log('Exiting process');
if (err) {
process.exit(1); // Non-zero failure code
} else {
process.exit(0);
}
}
process.on('SIGTERM', () => {
console.log('Received SIGTERM');
shutdown();
});
process.on('SIGINT', () => {
console.log('Received SIGINT');
shutdown();
});
process.on('uncaughtException', err => {
console.log('Uncaught exception');
console.error(err);
shutdown(err);
});