Module: FileWatch::ObservingBase

Included in:
ObservingRead, ObservingTail
Defined in:
lib/filewatch/observing_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



37
38
39
# File 'lib/filewatch/observing_base.rb', line 37

def settings
  @settings
end

#sincedb_collectionObject (readonly)

Returns the value of attribute sincedb_collection.



37
38
39
# File 'lib/filewatch/observing_base.rb', line 37

def sincedb_collection
  @sincedb_collection
end

#watchObject (readonly)

Returns the value of attribute watch.



37
38
39
# File 'lib/filewatch/observing_base.rb', line 37

def watch
  @watch
end

Instance Method Details

#build_watch_and_dependenciesObject



59
60
61
62
63
64
65
66
# 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

#initialize(opts = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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

#quitObject

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



80
81
82
83
84
# 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) ⇒ Object



72
73
74
75
# 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) ⇒ Object



68
69
70
# File 'lib/filewatch/observing_base.rb', line 68

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