Class: SuipitApp
Class Method Summary
collapse
inherited, registry, report
Class Method Details
.build_report(options) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/json_tail/parsers/suipit_app.rb', line 11
def build_report(options)
previous_datetime = (Time.now.utc - options['delay']).strftime("%Y-%m-%d %H:%M:%S")
conn = Mysql.connect(options['host'], options['username'], options['password'], options['database'])
loop do
content = {}
current_datetime = Time.now.utc.strftime("%Y-%m-%d %H:%M:%S")
query = %{SELECT (SELECT count(id) FROM mensajes WHERE created_at BETWEEN '#{previous_datetime}' AND '#{current_datetime}') as mensajes,
(SELECT count(id) FROM comentarios WHERE created_at BETWEEN '#{previous_datetime}' AND '#{current_datetime}') as comentarios,
(SELECT count(id) FROM archivos WHERE created_at BETWEEN '#{previous_datetime}' AND '#{current_datetime}') as archivos}
result = conn.query(query)
result.each do |row|
content = { "mensajes" => row[0], "comentarios" => row[1], "archivos" => row[2] }
end
report(options['parser'], content)
previous_datetime = current_datetime
sleep(options['interval'])
end
end
|