forked from odota/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.js
116 lines (116 loc) · 3.42 KB
/
status.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
var async = require('async');
var db = require('./db');
var r = require('./redis');
var redis = r.client;
var jobs = r.jobs;
module.exports = function getStatus(cb) {
console.time('status');
async.series({
matches: function(cb) {
db.matches.count({}, cb);
},
players: function(cb) {
db.players.count({}, cb);
},
user_players: function(cb) {
db.players.count({
last_visited: {
$gt: new Date(0)
}
}, cb);
},
full_history_players: function(cb) {
db.players.count({
full_history_time: {
$gt: new Date(0)
}
}, cb);
},
tracked_players: function(cb) {
redis.get("trackedPlayers", function(err, res) {
res = res ? Object.keys(JSON.parse(res)).length : 0;
cb(err, res);
});
},
rating_players: function(cb) {
redis.get("ratingPlayers", function(err, res) {
res = res ? Object.keys(JSON.parse(res)).length : 0;
cb(err, res);
});
},
donated_players: function(cb) {
redis.get("donators", function(err, res) {
res = res ? Object.keys(JSON.parse(res)).length : 0;
cb(err, res);
});
},
cached_players: function(cb) {
redis.keys("player:*", function(err, result) {
cb(err, result.length);
});
},
matches_last_day: function(cb) {
redis.keys("added_match:*", function(err, result) {
cb(err, result.length);
});
},
parsed_last_day: function(cb) {
redis.keys("parsed_match:*", function(err, result) {
cb(err, result.length);
});
},
/*
requested_last_day: function(cb) {
redis.keys("requested_match:*", function(err, result) {
cb(err, result.length);
});
},
*/
last_added: function(cb) {
db.matches.find({}, {
sort: {
_id: -1
},
fields: {
match_id: 1,
match_seq_num: 1,
start_time: 1,
duration: 1
},
limit: 10
}, cb);
},
last_parsed: function(cb) {
db.matches.find({
parse_status: 2
}, {
sort: {
_id: -1
},
fields: {
match_id: 1,
match_seq_num: 1,
start_time: 1,
duration: 1
},
limit: 10
}, cb);
},
kue: function(cb) {
var counts = {};
jobs.types(function(err, data) {
async.each(data, function(d, cb) {
jobs.cardByType(d, "inactive", function(err, result) {
counts[d] = result;
cb(err);
});
}, function(err) {
cb(err, counts);
});
});
}
}, function(err, results){
console.timeEnd('status');
cb(err, results);
});
};