Skip to content

Commit

Permalink
#58
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Dec 7, 2015
1 parent 807ba2a commit e60b051
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

# 0.5.6

- Don't mess with incoming error #37
- [#58] Clear all intervals when receiving kill signal from PM2 to free event loop
- [#37] Don't mess with incoming error
- right pmx version injected into module
- if pmx cannot find package.json in current folder, try to require in parent folder
- disable some error messages
Expand Down
13 changes: 13 additions & 0 deletions lib/Probe.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ Probe.probe = function() {
});
checkIssues(Probe._var);
}, 990);

// Clear probes data cooking on SIGINT (first PM2 signal when killing);
process.on('SIGINT', function stopProbeInterval() {
clearInterval(p_interval);

// == 1 because there is also a set interval in probes/pacemaker.js
if (process.listeners('SIGINT').filter(function (listener) {
return listener !== stopProbeInterval;
}).length == 1) {
process.exit(0);
}
});

}

return {
Expand Down
8 changes: 7 additions & 1 deletion lib/probes/pacemaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ module.exports = function(pmx) {
unit : 'ms'
});

setInterval(function() {
var pace_interval = setInterval(function() {
var newTime = process.hrtime();
var delay = (newTime[0] - oldTime[0]) * 1e3 + (newTime[1] - oldTime[1]) / 1e6 - TIME_INTERVAL;
oldTime = newTime;
histogram.update(delay);
}, TIME_INTERVAL);

// Clear pacemaker interval cooking on SIGINT (first PM2 signal when killing);
process.on('SIGINT', function stopIntervalSIGINT() {
clearInterval(pace_interval);
});

};

0 comments on commit e60b051

Please sign in to comment.