From 9b97414bd2bc92bfba0ae3059361e8c58fc8c04d Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Thu, 23 Feb 2017 09:55:59 +0100
Subject: [PATCH] Make sure that only one PhantomJS process is running at any
 single time

---
 plugins/reporting/index.js | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/plugins/reporting/index.js b/plugins/reporting/index.js
index 0298235..07a6a93 100644
--- a/plugins/reporting/index.js
+++ b/plugins/reporting/index.js
@@ -23,9 +23,6 @@ exports.initWebApp = function(options) {
   var count = 0;
 
   Ping.on('afterInsert', function(ping) {
-    if (count > 1) {
-      return;
-    }
     Check.findById(ping.check, function(err, check) {
       if (err) {
         return;
@@ -45,13 +42,17 @@ exports.initWebApp = function(options) {
         }
       }
 
+      if (count > 0) {
+        return;
+      }
+      count++;
+      console.log('PhantomJS started, currently ' + count + ' processes.');
+
       // Create the report
       var phantomjs = require('phantomjs-prebuilt'),
           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);
 
-      count++;
-      console.log('PhantomJS started, currently ' + count + ' processes.');
       program.on('exit', function() {
         count--;
         console.log('PhantomJS finished');
-- 
GitLab