Class: DatabaseStalker::LogStalker
- Inherits:
-
Object
- Object
- DatabaseStalker::LogStalker
- Defined in:
- lib/database_stalker/log_stalker.rb
Instance Method Summary collapse
-
#initialize(stalked_file_path, stalking_result_path) ⇒ LogStalker
constructor
A new instance of LogStalker.
- #result ⇒ Object
- #run ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(stalked_file_path, stalking_result_path) ⇒ LogStalker
Returns a new instance of LogStalker.
6 7 8 9 |
# 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 |
Instance Method Details
#result ⇒ Object
25 26 27 28 29 30 31 32 33 |
# 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 ⇒ Object
11 12 13 14 15 |
# 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 ⇒ Object
17 18 19 20 21 22 23 |
# 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 |