-
Notifications
You must be signed in to change notification settings - Fork 1
/
sync.js
72 lines (63 loc) · 1.72 KB
/
sync.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
const Synchronizer = require('./app/Synchronizer');
const helper = require('./app/common/helper');
const logger = helper.getLogger('Sync');
const ExplorerError = require('./app/common/ExplorerError');
const args = process.argv.slice(2);
let synchronizer;
async function start() {
logger.debug('Start synchronizer');
synchronizer = new Synchronizer(args);
await synchronizer.initialize();
console.log('\n');
console.log(`Synchronizer pid is ${process.pid}`);
console.log('\n');
}
start();
// this function is called when you want the server to die gracefully
// i.e. wait for existing connections
const shutDown = function () {
console.log(
'<<<<<<<<<<<<<<<<<<<<<<<<<< Closing client processor >>>>>>>>>>>>>>>>>>>>>'
);
if (synchronizer) {
synchronizer.close();
}
setTimeout(() => {
process.exit(0);
setTimeout(() => {
console.error(
'Could not close child connections in time, forcefully shutting down'
);
if (synchronizer) {
synchronizer.close();
}
process.exit(1);
}, 5000);
}, 2000);
};
process.on('unhandledRejection', (up) => {
console.log(
'<<<<<<<<<<<<<<<<<<<<<<<<<< Synchronizer Error >>>>>>>>>>>>>>>>>>>>>'
);
if (up instanceof ExplorerError) {
console.log('Error : ', up.message);
} else {
console.log(up);
}
shutDown();
});
process.on('uncaughtException', (up) => {
console.log(
'<<<<<<<<<<<<<<<<<<<<<<<<<< Synchronizer Error >>>>>>>>>>>>>>>>>>>>>'
);
if (up instanceof ExplorerError) {
console.log('Error : ', up.message);
} else {
console.log(up);
}
shutDown();
});
// listen for TERM signal .e.g. kill
process.on('SIGTERM', shutDown);
// listen for INT signal e.g. Ctrl-C
process.on('SIGINT', shutDown);