Skip to content
Snippets Groups Projects
Commit 28a2c8a6 authored by jurgenhaas's avatar jurgenhaas
Browse files

#9 Take screenshots only every 6 hours

parent d749187e
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@ exports.initWebApp = function(options) {
var count = 0;
Ping.on('afterInsert', function(ping) {
if (count > 3) {
if (count > 1) {
return;
}
Check.findById(ping.check, function(err, check) {
......@@ -34,10 +34,21 @@ exports.initWebApp = function(options) {
return;
}
var output = '/var/log/nodejs/reports/' + check.name + '.png',
date = Date.now();
if (fs.existsSync(output)) {
var stat = fs.statSync(output),
fdate = new Date(stat.mtime);
if ((fdate + 21600000) > date) {
// Only refresh the file if it's old than 6 hours
return;
}
}
// 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, check.name, 'month', Date.now());
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.');
......
......@@ -5,7 +5,7 @@ var page = require('webpage').create(),
username = args[2],
password = args[3],
check = args[4],
name = args[5],
output = args[5],
type = args[6],
date = args[7],
fullUrl = url + '/dashboard/checks/' + check + '?type=' + type + '&date=' + date;
......@@ -13,6 +13,6 @@ var page = require('webpage').create(),
page.settings.userName = username;
page.settings.password = password;
page.open(fullUrl, function() {
page.render('/var/log/nodejs/reports/' + name + '.png');
page.render(output);
phantom.exit();
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment