Class: FileWatch::YieldingTail
- Inherits:
-
Object
- Object
- FileWatch::YieldingTail
- Includes:
- TailBase
- Defined in:
- lib/filewatch/yielding_tail.rb
Constant Summary
Constants included from TailBase
Instance Attribute Summary
Attributes included from TailBase
Instance Method Summary collapse
Methods included from TailBase
#close_file, #initialize, #quit, #sincedb_record_uid, #sincedb_write, #tail
Instance Method Details
#subscribe(&block) ⇒ Object
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/filewatch/yielding_tail.rb', line 8 def subscribe(&block) # subscribe(stat_interval = 1, discover_interval = 5, &block) @watch.subscribe(@opts[:stat_interval], @opts[:discover_interval]) do |event, watched_file| path = watched_file.path file_is_open = watched_file.file_open? case event when :unignore _add_to_sincedb(watched_file, event) when :create, :create_initial if file_is_open @logger.debug? && @logger.debug("#{event} for #{path}: file already open") next end if _open_file(watched_file, event) yield_read_file(watched_file, &block) end when :modify if !file_is_open @logger.debug? && @logger.debug(":modify for #{path}, file is not open, opening now") if _open_file(watched_file, event) yield_read_file(watched_file, &block) end else yield_read_file(watched_file, &block) end when :delete if file_is_open @logger.debug? && @logger.debug(":delete for #{path}, closing file") yield_read_file(watched_file, &block) watched_file.file_close else @logger.debug? && @logger.debug(":delete for #{path}, file already closed") end when :timeout @logger.debug? && @logger.debug(":timeout for #{path}, closing file") watched_file.file_close else @logger.warn("unknown event type #{event} for #{path}") end end # @watch.subscribe # when watch.subscribe ends - its because we got quit _sincedb_write end |