-
Notifications
You must be signed in to change notification settings - Fork 0
/
pbs3.rb
35 lines (32 loc) · 1.08 KB
/
pbs3.rb
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
require "net/http"
require_relative "logs_parser"
game_name = ARGV[0]
players_count = ARGV[1].to_i
last_line_read = ARGV[2].to_i || 0
host = ARGV[3] || "fierce-reaches-40697.herokuapp.com"
parser = LogsParser::Service.new(game_name, players_count)
http_adapter = LogsParser::HttpAdapter.new(host: host)
iterations_counter = 0
loop do
puts "Iteration #{iterations_counter}"
puts "Processing log file from line #{last_line_read}..."
lines_counter = 0
previous_last_line_read = last_line_read
IO.foreach("net_message_debug.log") do |line|
begin
if lines_counter >= previous_last_line_read
if result = parser.call(line)
response = http_adapter.send_data(result)
puts response.inspect
end
end
lines_counter += 1
last_line_read = lines_counter
rescue LogsParser::HttpAdapter::NetworkError, LogsParser::HttpAdapter::ServerError => e
puts "Error sending data: #{e.class} - #{e.message}"
puts "Data starting from line #{last_line_read} will be retransmitted soon."
end
end
iterations_counter += 1
sleep 60
end