Class: FileWatch::YieldingTail

Inherits:
Object
  • Object
show all
Includes:
TailBase
Defined in:
lib/filewatch/yielding_tail.rb

Constant Summary

Constants included from TailBase

TailBase::OPEN_WARN_INTERVAL

Instance Attribute Summary

Attributes included from TailBase

#logger

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
# 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, path|
    case event
    when :create, :create_initial
      if @files.member?(path)
        @logger.debug? && @logger.debug("#{event} for #{path}: already exists in @files")
        next
      end
      if _open_file(path, event)
        yield_read_file(path, &block)
      end
    when :modify
      if !@files.member?(path)
        @logger.debug? && @logger.debug(":modify for #{path}, does not exist in @files")
        if _open_file(path, event)
          yield_read_file(path, &block)
        end
      else
        yield_read_file(path, &block)
      end
    when :delete
      @logger.debug? && @logger.debug(":delete for: #{path} - closed and deleted from @files")
      if @files[path]
        yield_read_file(path, &block)
        @files[path].close
      end
      @files.delete(path)
      @statcache.delete(path)
    when :timeout
      @logger.debug? && @logger.debug(":timeout for: #{path} - closed and deleted from @files")
      if (deleted = @files.delete(path))
        deleted.close
      end
      @statcache.delete(path)
    else
      @logger.warn("unknown event type #{event} for #{path}")
    end
  end # @watch.subscribe
end