main.coffee
2.19 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
72
config = require('../config/main.js')
fs = require('fs')
kue = require('kue')
queue = kue.createQueue()
exports = module.exports = {}
# 1 - Core retornou um erro.
# 2 - Vídeo inválido.
# 3 - Legenda inválida.
# 4 - Endpoint inválido.
# params_box = JSON.parse(fs.readFileSync('./config/params_box.json', 'utf8'))
# errors = JSON.parse(fs.readFileSync('./logsystem/errors.log', 'utf8'))
# services = JSON.parse(fs.readFileSync('./logsystem/services.log', 'utf8'))
writeLog = (file, path) ->
fs.writeFileSync path, JSON.stringify(file, null, 4)
exports.incrementError = (id, detalhe="", inc=1) ->
errors_log_path = "./logsystem/errors.log"
errors = JSON.parse(fs.readFileSync(errors_log_path, 'utf8'))
bloqueante = !config.isNaoBloqueante() # diferente de nao bloqueante aceita bloqueante ou ambos
# id pode ser "1", "2", "3", "4" ou qualquer outro id criado para identificar erros
# 1 ou 'core' - Core retornou um erro.
# 2 ou 'video' - Vídeo inválido.
# 3 ou 'legenda' - Legenda inválida.
# 4 ou 'endpoint' - Endpoint inválido.
switch id
when 'core' then id = "1"
when 'video' then id = "2"
when 'legenda' then id = "3"
when 'endpoint' then id = "4"
else
console.log("ID inválido")
if bloqueante
errors["resumo"]["bloqueante"][id] += inc
else
errors["resumo"]["nao-bloqueante"][id] += inc
errors["detalhado"][id] = detalhe
writeLog(errors, errors_log_path)
exports.incrementService = (serviceType, type, 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
writeLog(services, services_log_path)
exports.updateHealth = (serviceType="outros", value=0) ->
services_log_path = "./logsystem/services.log"
services = JSON.parse(fs.readFileSync(services_log_path, 'utf8'))
# if e else if pra excluir valores diferente desses dois
if serviceType == "videos"
services["tipo"]["videos"]["saude"] = value
else if serviceType == "outros"
services["tipo"]["outros"]["saude"] = value
writeLog(services, services_log_path)