Run each script and kill it (control + c). When scraper is required, we cannot hook into process.on callbacks
Created
September 29, 2015 22:44
-
-
Save erikhazzard/84dca1dae510c671a537 to your computer and use it in GitHub Desktop.
Scraper process callback examples
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
/** | |
* If scraper is not included, callback gets called | |
*/ | |
process.on('SIGINT', function(){ | |
console.log('Hello I get called'); | |
process.exit(1); | |
}); | |
setTimeout(function(){}, 19000); // keep alive |
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
/** | |
* If scraper is included before process.on calls, the callbacks never get called | |
*/ | |
var scraperjs = require('scraperjs'); | |
process.on('SIGINT', function(){ | |
console.log('Hello I never get called'); | |
process.exit(1); | |
}); | |
setTimeout(function(){}, 19000); // keep alive |
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
/** | |
* If scraper is not included, callbacks are all called | |
*/ | |
function close() { | |
console.log('Received SIGINT...emitting cleanup\n'); | |
process.emit('cleanup'); | |
setTimeout(function() { | |
console.log('>>>>>>>>>> Exiting \n'); | |
process.exit(1); | |
}, 1000); | |
} | |
process.on('SIGINT', close); | |
process.on('cleanup', function(){ | |
console.log("<<< CLEANING >>>"); | |
setTimeout(function(){ | |
console.log('<<< TIMEOUT CALLED >>>'); | |
}, 100); | |
}); | |
setTimeout(function(){}, 19000); // keep alive |
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
/** | |
* If scraperjs is included after everything is set up, the timeout in process.on('cleanup') | |
* is never called. | |
*/ | |
function close() { | |
console.log('Received SIGINT...emitting cleanup\n'); | |
process.emit('cleanup'); | |
setTimeout(function() { | |
console.log('>>>>>>>>>> Exiting \n'); | |
process.exit(1); | |
}, 1000); | |
} | |
process.on('SIGINT', close); | |
process.on('cleanup', function(){ | |
console.log("<<< CLEANING >>>"); | |
setTimeout(function(){ | |
console.log('<<< THIS IS NEVER CALLED >>>'); | |
}, 100); | |
}); | |
setTimeout(function(){}, 19000); // keep alive | |
// If we import it down here, the initial process signal is caught, but timeout | |
// callbacks never get called | |
var scraperjs = require('scraperjs'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment