-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug in Scribe transcript rolling
- Loading branch information
1 parent
9b41afa
commit 7b260f6
Showing
3 changed files
with
43 additions
and
59 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,31 @@ | ||
// Handles graceful application specific cleanup to avoid hung servers... | ||
|
||
var cleanup = { | ||
// define a default callback reference to be overridden by application... | ||
callback: null, | ||
// flag to prevent circular calls. | ||
called: false, | ||
// define a function to call for graceful exiting... | ||
delay: 400, | ||
gracefulExit: function (code) { | ||
if (!this.called) { | ||
this.called = true; | ||
console.log("Graceful exit cleanup..."); | ||
if (this.callback) this.callback(); // do app specific cleaning once before exiting | ||
code = (code!==undefined) ? code : 1; // assume non-zero (i.e. error) if not explicit | ||
setTimeout(function() {process.exit(code);},this.delay); // no stopping! | ||
}; | ||
} | ||
}; | ||
|
||
// clean exit test... | ||
process.on('beforeExit', | ||
function () { | ||
cleanup.gracefulExit(0); | ||
} | ||
); | ||
|
||
// catch ctrl+c event and exit gracefully | ||
process.on('SIGINT', | ||
function () { | ||
cleanup.gracefulExit(2); | ||
} | ||
); | ||
|
||
//catch uncaught exceptions, trace, then exit gracefully... | ||
process.on('uncaughtException', | ||
function(e) { | ||
console.log('Uncaught Exception...'); | ||
console.log(e.stack); | ||
cleanup.gracefulExit(99); | ||
} | ||
); | ||
|
||
|
||
module.exports = init = function init(cb=null) { | ||
cleanup.callback = cb; | ||
return cleanup; | ||
}; | ||
// Handles graceful application specific cleanup to avoid hung servers... | ||
|
||
var cleanup = { | ||
callback: ()=>console.log("Graceful exit ..."), // default callback | ||
called: false, // flag to prevent circular calls. | ||
delay: 400, | ||
gracefulExit: function (code=1) { // graceful exit call... | ||
if (!this.called) { | ||
this.called = true; | ||
this.callback(); // do app specific cleaning once before exiting | ||
setTimeout(process.exit,this.delay,code); // no stopping! | ||
}; | ||
} | ||
}; | ||
|
||
// catch clean exit ... | ||
process.on('beforeExit', function () { cleanup.gracefulExit(0); }); | ||
|
||
// catch ctrl+c event and exit gracefully | ||
process.on('SIGINT', function () { cleanup.gracefulExit(2); }); | ||
|
||
//catch uncaught exceptions, trace, then exit gracefully... | ||
process.on('uncaughtException', | ||
function(e) { | ||
console.log('Uncaught Exception...'); | ||
console.log(e.stack); | ||
cleanup.gracefulExit(99); | ||
} | ||
); | ||
|
||
module.exports = init = (cb)=>{cleanup.callback=cb||null; return cleanup;}; |
This file contains 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
This file contains 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