-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
37 lines (31 loc) · 817 Bytes
/
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
'use strict';
var config = require('./config');
var storage = require('./storage');
var cbToCall;
var process = global.process;
function isProcessOk(process) {
return process &&
typeof process === 'object' &&
typeof process.kill === 'function' &&
typeof process.pid === 'number' &&
typeof process.on === 'function'
}
function reloadCbFn(cb) {
cbToCall = cb;
storage.write(process.pid.toString());
};
process.on(config.SIGNAL_EVENT, function() {
if (typeof cbToCall === 'function') {
cbToCall();
} else {
console.error('SIGPIPE triggered but no callback provided to execute');
}
});
if (!isProcessOk(process)) {
console.error('Invalid nodejs process object detected')
module.exports = function () {
return function () {}
}
} else {
module.exports = reloadCbFn;
}