Skip to content
Snippets Groups Projects
Commit 9b97414b authored by jurgenhaas's avatar jurgenhaas
Browse files

Make sure that only one PhantomJS process is running at any single time

parent cc0e6a3d
No related branches found
No related tags found
No related merge requests found
...@@ -23,9 +23,6 @@ exports.initWebApp = function(options) { ...@@ -23,9 +23,6 @@ exports.initWebApp = function(options) {
var count = 0; var count = 0;
Ping.on('afterInsert', function(ping) { Ping.on('afterInsert', function(ping) {
if (count > 1) {
return;
}
Check.findById(ping.check, function(err, check) { Check.findById(ping.check, function(err, check) {
if (err) { if (err) {
return; return;
...@@ -45,13 +42,17 @@ exports.initWebApp = function(options) { ...@@ -45,13 +42,17 @@ exports.initWebApp = function(options) {
} }
} }
if (count > 0) {
return;
}
count++;
console.log('PhantomJS started, currently ' + count + ' processes.');
// Create the report // Create the report
var phantomjs = require('phantomjs-prebuilt'), var phantomjs = require('phantomjs-prebuilt'),
path = require('path'), path = require('path'),
program = phantomjs.exec(path.join(__dirname, 'phantomjs-script.js'), config['url'], config['basicAuth']['username'], config['basicAuth']['password'], check._id, output, 'month', date); program = phantomjs.exec(path.join(__dirname, 'phantomjs-script.js'), config['url'], config['basicAuth']['username'], config['basicAuth']['password'], check._id, output, 'month', date);
count++;
console.log('PhantomJS started, currently ' + count + ' processes.');
program.on('exit', function() { program.on('exit', function() {
count--; count--;
console.log('PhantomJS finished'); console.log('PhantomJS finished');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment