Created
April 10, 2014 15:00
-
-
Save titarenko/10391325 to your computer and use it in GitHub Desktop.
Exit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var log = require('../core/log'); | |
| var memwatch = require('memwatch'); | |
| function exit () { | |
| // temporal failure, user is invited to restart | |
| // (according to http://stackoverflow.com/a/1535733) | |
| process.exit(75); | |
| } | |
| exit.whenUncaughtException = function () { | |
| process.on('uncaughtException', function (error) { | |
| exit(); | |
| }); | |
| return exit; | |
| }; | |
| exit.whenMemoryLimit = function (limit) { | |
| memwatch.on('stats', function (info) { | |
| if (info.current_base > limit) { | |
| log.info('Exceeded memory limit.', info.current_base.toString(), '>', limit.toString()) | |
| exit(); | |
| } | |
| }); | |
| return exit; | |
| } | |
| module.exports = exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment