class Rreplay::ReplayRunner

Public Class Methods

new(endpoint, target, format: :msgpack, debug: false) click to toggle source
# File lib/rreplay/replay_runner.rb, line 11
def initialize(endpoint, target, format: :msgpack, debug: false)
  @http = Http.new(endpoint)
  @format = Rreplay::Format.of(format)
  @target = target
  @debugger = Debugger.new($stdout, debug)
end

Public Instance Methods

run() click to toggle source
# File lib/rreplay/replay_runner.rb, line 18
def run
  output = OutputBuilder.new(style: :json)

  file_names.each do |file_name|
    ::File.open(file_name) do |file|
      @debugger.out { { message: "Open file: #{file_name}" } }

      file.each_line do |line|
        next if line.start_with?('#') # LogDevice's header
        line.chomp!
        record = deserialize(line)

        result = @http.call(record['request'])
        @debugger.out {
          output.call(record, result)
        }
      end
    end
  end
rescue Interrupt
  @debugger.out { "Interrupted." }
end

Private Instance Methods

deserialize(line) click to toggle source
# File lib/rreplay/replay_runner.rb, line 52
def deserialize(line)
  @format.deserializer.call(line)
rescue => e
  raise "Failed to deserialize. err = #{e.inspect}, line = #{line}", e
end
file_names() click to toggle source
# File lib/rreplay/replay_runner.rb, line 43
def file_names
  if ::File.directory?(@target)
    ::Dir.glob(::File.join(@target,
                           ::Rreplay::LOG_FILE_NAME_PREFIX + @format.file_suffix + "*"))
  else
    Array(@target)
  end
end