This repository was archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathfixuptime_check.js
65 lines (53 loc) · 1.52 KB
/
fixuptime_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var mongoose = require('mongoose');
var async = require("async");
mongoose.connect('mongodb://localhost:27017/mynanoninja',
{ useNewUrlParser: true }
);
var Account = require('../models/account');
var Check = require('../models/check');
var end = new Date(Date.now());
var begin = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
Account.find({
uptime: { $gt: 0 },
lastVoted: { $gt: begin }
})
.exec(function (err, accounts) {
if (err) {
console.error('Update', err);
return
}
console.log('== Update: ' + accounts.length + " accounts");
async.forEachOfSeries(accounts, (account, key, callback) => {
Check.find({
timestamp: { $gte: begin, $lte: end },
isUp: false,
'account': account._id
})
.exec(function (err, checks) {
if (err) {
console.error('Update', err);
return
}
console.log('== Update: ' + checks.length + " checks", account.account, account.uptime);
async.forEachOfSeries(checks, (check, key, callback) => {
check.isUp = true;
check.save(function(){
callback()
})
}, err => {
if (err) {
console.error(err.message);
return
}
console.log('== Update for account done');
callback()
});
});
}, err => {
if (err) {
console.error(err.message);
return
}
console.log('== Update done');
});
});