-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathapp.js
55 lines (44 loc) · 1.78 KB
/
app.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
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
function init() {
const config = require('./models/config')
//init storage and persistence layer
const storage = require('./logic/storage')
return storage.init(config)
.then(() => {
process.on('SIGINT', () => {
shutdown()
})
process.on('SIGTERM', () => {
shutdown()
})
//init and start observer
const observer = require('./logic/observer')
observer.start()
//init HTTP server and map all API routes
const server = require('./api/server-initialization')(config)
function shutdown() {
console.log('Received kill signal')
console.log('Closing http server.')
server.close(() => {
observer.stop()
console.log('transaction observer stopped')
storage.finalize()
.then(()=>{
console.log('Storage provider connection closed.')
console.log('Closed out remaining connections')
process.exit(0)
})
.catch((err)=>{
console.error('Error closing connection '+ err)
console.error('Forcelly shutting down')
process.exit(1)
})
})
setTimeout(() => {
console.error('Could not close connections in time, forcefully shutting down')
process.exit(1)
}, 10000)
}
})
}
module.exports = init()