module FileWatch::ObservingBase

Attributes

settings[R]
sincedb_collection[R]
watch[R]

Public Class Methods

new(opts={}) click to toggle source
# File lib/filewatch/observing_base.rb, line 39
def initialize(opts={})
  options = {
    :sincedb_write_interval => 10,
    :stat_interval => 1,
    :discover_interval => 5,
    :exclude => [],
    :start_new_files_at => :end,
    :delimiter => "\n",
    :file_chunk_count => MAX_ITERATIONS,
    :file_chunk_size => FILE_READ_SIZE,
    :file_sort_by => "last_modified",
    :file_sort_direction => "asc",
  }.merge(opts)
  unless options.include?(:sincedb_path)
    raise NoSinceDBPathGiven.new("No sincedb_path set in options. This should have been added in the main LogStash::Inputs::File class")
  end
  @settings = Settings.from_options(options)
  build_watch_and_dependencies
end

Public Instance Methods

build_watch_and_dependencies() click to toggle source
# File lib/filewatch/observing_base.rb, line 59
def build_watch_and_dependencies
  logger.info("START, creating Discoverer, Watch with file and sincedb collections")
  watched_files_collection = WatchedFilesCollection.new(@settings)
  @sincedb_collection = SincedbCollection.new(@settings)
  @sincedb_collection.open
  discoverer = Discoverer.new(watched_files_collection, @sincedb_collection, @settings)
  @watch = Watch.new(discoverer, build_specific_processor(@settings), @settings)
end
quit() click to toggle source

quit is a sort-of finalizer, it should be called for clean up before the instance is disposed of.

# File lib/filewatch/observing_base.rb, line 80
def quit
  logger.info("QUIT - closing all files and shutting down.")
  @watch.quit # <-- should close all the files
  # sincedb_write("shutting down")
end
sincedb_write(reason=nil) click to toggle source
# File lib/filewatch/observing_base.rb, line 72
def sincedb_write(reason=nil)
  # can be invoked from the file input
  @sincedb_collection.write(reason)
end
watch_this(path) click to toggle source
# File lib/filewatch/observing_base.rb, line 68
def watch_this(path)
  @watch.watch(path)
end