forked from SockDrawer/SockSite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.js
41 lines (39 loc) · 1.14 KB
/
check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
var db = require('./database'),
config = require('./config.json'),
async = require('async'),
request = require('request');
var checkers = config.checks.map(function (url) {
return createCheck(url);
}),
delay = (config.pollDelay || 15) * 1000;
function createCheck(url) {
return function sitehome(next) {
var now = Date.now();
request(url, function (err, resp) {
var complete = Date.now() - now;
if (err) {
return db.addCheck(url, 599, 0, complete, function () {
next();
});
}
db.addCheck(url, resp.statusCode, (resp.body || '').length,
complete,
function () {
next();
});
});
};
}
exports.updated = false;
exports.start = function () {
async.forever(function (next) {
async.eachSeries(checkers, function (check, callback) {
exports.updated = true;
check(function () {
setTimeout(callback, delay);
});
},
next);
});
};