Class: Carnivore::Files::Util::Fetcher::Poll
- Inherits:
-
Carnivore::Files::Util::Fetcher
- Object
- Carnivore::Files::Util::Fetcher
- Carnivore::Files::Util::Fetcher::Poll
- Defined in:
- lib/carnivore-files/util/poll.rb
Overview
Polling fetcher
Instance Attribute Summary
Attributes inherited from Carnivore::Files::Util::Fetcher
#delimiter, #io, #messages, #path
Instance Method Summary collapse
-
#destroy_io ⇒ TrueClass
Destroy the IO instance and monitor.
-
#start_fetcher ⇒ Object
Start the fetcher.
-
#wait_for_file ⇒ TrueClass
Wait helper for file to appear (2 second intervals).
Methods inherited from Carnivore::Files::Util::Fetcher
#build_io, #initialize, #retrieve_lines, #write_line
Constructor Details
This class inherits a constructor from Carnivore::Files::Util::Fetcher
Instance Method Details
#destroy_io ⇒ TrueClass
Destroy the IO instance and monitor
36 37 38 39 40 41 42 |
# File 'lib/carnivore-files/util/poll.rb', line 36 def destroy_io if(io) io.close @io = nil end true end |
#start_fetcher ⇒ Object
Start the fetcher
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/carnivore-files/util/poll.rb', line 12 def start_fetcher loop do build_io ino = io.stat.ino retrieve_lines.each do |line| self. << line end pos = io.pos sleep(1) begin if(io.size < pos || ino != File.stat(path).ino) destroy_io @waited = true end rescue Errno::ENOENT destroy_io @waited = true end end end |
#wait_for_file ⇒ TrueClass
Wait helper for file to appear (2 second intervals)
47 48 49 50 51 52 53 54 |
# File 'lib/carnivore-files/util/poll.rb', line 47 def wait_for_file warn "Waiting for file to appear (#{path})" until(::File.exists?(path)) @waited = true sleep(2) end info "File has appeared (#{path})!" end |