main.js
1.96 KB
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
(function() {
var config, exports, fs, kue, queue, writeLog;
config = require('../config/main.js');
fs = require('fs');
kue = require('kue');
queue = kue.createQueue();
exports = module.exports = {};
writeLog = function(file, path) {
return fs.writeFileSync(path, JSON.stringify(file, null, 4));
};
exports.incrementError = function(id, detalhe, inc) {
var bloqueante, errors, errors_log_path;
if (detalhe == null) {
detalhe = "";
}
if (inc == null) {
inc = 1;
}
errors_log_path = "./logsystem/errors.log";
errors = JSON.parse(fs.readFileSync(errors_log_path, 'utf8'));
bloqueante = !config.isNaoBloqueante();
if (bloqueante) {
errors["resumo"]["bloqueante"][id] += inc;
} else {
errors["resumo"]["nao-bloqueante"][id] += inc;
}
errors["detalhado"][id] = detalhe;
return writeLog(errors, errors_log_path);
};
exports.incrementService = function(serviceType, type, inc) {
var services, services_log_path;
if (inc == null) {
inc = 1;
}
services_log_path = "./logsystem/services.log";
services = JSON.parse(fs.readFileSync(services_log_path, 'utf8'));
if (serviceType === "videos") {
services["tipo"]["videos"][type] += inc;
} else if (serviceType === "outros") {
services["tipo"]["outros"][type] += inc;
}
return writeLog(services, services_log_path);
};
exports.updateHealth = function(serviceType, value) {
var services, services_log_path;
if (serviceType == null) {
serviceType = "outros";
}
if (value == null) {
value = 0;
}
services_log_path = "./logsystem/services.log";
services = JSON.parse(fs.readFileSync(services_log_path, 'utf8'));
if (serviceType === "videos") {
services["tipo"]["videos"]["saude"] = value;
} else if (serviceType === "outros") {
services["tipo"]["outros"]["saude"] = value;
}
return writeLog(services, services_log_path);
};
}).call(this);