class DatabaseStalker::LogStalker

Public Class Methods

new(stalked_file_path, stalking_result_path) click to toggle source
# File lib/database_stalker/log_stalker.rb, line 6
def initialize(stalked_file_path, stalking_result_path)
  @stalked_file_path = stalked_file_path
  @stalking_result_path = stalking_result_path
end

Public Instance Methods

result() click to toggle source
# File lib/database_stalker/log_stalker.rb, line 25
def result
  result = []
  File.open(@stalking_result_path) do |file|
    file.each_line do |line|
      result << line
    end
  end
  result
end
run() click to toggle source
# File lib/database_stalker/log_stalker.rb, line 11
def run
  @runned_tails = Util.runned_tail_pids
  spawn("tail -f -n 0 #{@stalked_file_path} > #{@stalking_result_path}")
  wait_for_tail_process_runninng
end
stop() click to toggle source
# File lib/database_stalker/log_stalker.rb, line 17
def stop
  wait_for_tail_process_output
  current_runned_tails = Util.runned_tail_pids
  (current_runned_tails - @runned_tails).each do |pid|
    Process.kill('KILL', pid)
  end
end

Private Instance Methods

wait_for_tail_process_output() click to toggle source
# File lib/database_stalker/log_stalker.rb, line 42
def wait_for_tail_process_output
  sleep(0.01)
end
wait_for_tail_process_runninng() click to toggle source
# File lib/database_stalker/log_stalker.rb, line 38
def wait_for_tail_process_runninng
  sleep(0.01)
end