Class: FileWatch::Ext::TailBase

Inherits:
Object
  • Object
show all
Defined in:
lib/filewatch/ext/tailbase.rb

Direct Known Subclasses

FileTail, XlsTail, XlsxTail

Defined Under Namespace

Classes: NoSinceDBPathGiven

Constant Summary collapse

OPEN_WARN_INTERVAL =

how often (in seconds) we @logger.warn a failed file open, per path.

ENV["FILEWATCH_OPEN_WARN_INTERVAL"] ?
ENV["FILEWATCH_OPEN_WARN_INTERVAL"].to_i : 300

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ TailBase

Returns a new instance of TailBase.



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
53
54
55
56
57
# File 'lib/filewatch/ext/tailbase.rb', line 22

def initialize(opts={})
  @iswindows = ((RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/) != nil)

  if opts[:logger]
    @logger = opts[:logger]
  else
    @logger = Logger.new(STDERR)
    @logger.level = Logger::INFO
  end
  @files = {}
  @lastwarn = Hash.new { |h, k| h[k] = 0 }
  @watch = FileWatch::Watch.new
  @watch.logger = @logger
  @sincedb = {}
  @sincedb_last_write = 0
  @statcache = {}
  @opts = {
    :sincedb_write_interval => 10,
    :stat_interval => 1,
    :discover_interval => 5,
    :exclude => [],
    :start_new_files_at => :end,
    :progressdb => false,
    :eof_close => false,
  }.merge(opts)
  if !@opts.include?(:sincedb_path)
    @opts[:sincedb_path] = File.join(ENV["HOME"], ".sincedb") if ENV.include?("HOME")
    @opts[:sincedb_path] = ENV["SINCEDB_PATH"] if ENV.include?("SINCEDB_PATH")
  end
  if !@opts.include?(:sincedb_path)
    raise NoSinceDBPathGiven.new("No HOME or SINCEDB_PATH set in environment. I need one of these set so I can keep track of the files I am following.")
  end
  @watch.exclude(@opts[:exclude])

  _sincedb_open
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



17
18
19
# File 'lib/filewatch/ext/tailbase.rb', line 17

def logger
  @logger
end

Instance Method Details

#quitObject



185
186
187
# File 'lib/filewatch/ext/tailbase.rb', line 185

def quit
  @watch.quit
end

#sincedb_write(reason = nil) ⇒ Object



103
104
105
106
# File 'lib/filewatch/ext/tailbase.rb', line 103

def sincedb_write(reason=nil)
  @logger.debug("caller requested sincedb write (#{reason})")
  _sincedb_write
end

#subscribe(&block) ⇒ Object



71
72
73
# File 'lib/filewatch/ext/tailbase.rb', line 71

def subscribe(&block)
  # to be overwritten
end

#tail(path) ⇒ Object



66
67
68
# File 'lib/filewatch/ext/tailbase.rb', line 66

def tail(path)
  @watch.watch(path)
end