Class: Franz::Discover
- Inherits:
-
Object
- Object
- Franz::Discover
- Defined in:
- lib/franz/discover.rb
Overview
Discover performs half of file existence detection by expanding globs and keeping track of files known to Franz. Discover requires a deletions Queue to maintain this state, so it’s fairly useless without a Watch.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Discover
constructor
Start a new Discover thread in the background.
-
#state ⇒ Object
Return the internal “known” state.
-
#stop ⇒ Array
Stop the Discover thread.
Constructor Details
#initialize(opts = {}) ⇒ Discover
Start a new Discover thread in the background.
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/franz/discover.rb', line 20 def initialize opts={} @ic = opts[:input_config] || raise('No input_config specified') @discoveries = opts[:discoveries] || [] @deletions = opts[:deletions] || [] @discover_interval = opts[:discover_interval] || 30 @known = opts[:known] || [] @logger = opts[:logger] || Logger.new(STDOUT) @known = Set.new(@known) @configs = @ic.configs.map do |config| config[:includes] ||= [] config[:excludes] ||= [] config end @stop = false @thread = Thread.new do until @stop until deletions.empty? d = deletions.pop @known.delete d log.debug \ event: 'discover deleted', path: d end discover.each do |discovery| discoveries.push discovery @known.add discovery log.debug \ event: 'discover discovered', path: discovery end sleep discover_interval end end log.debug \ event: 'discover started', discoveries: discoveries, deletions: deletions, discover_interval: discover_interval end |
Instance Method Details
#state ⇒ Object
Return the internal “known” state
81 82 83 |
# File 'lib/franz/discover.rb', line 81 def state return @known.to_a end |
#stop ⇒ Array
Stop the Discover thread. Effectively only once.
72 73 74 75 76 77 78 |
# File 'lib/franz/discover.rb', line 72 def stop return state if @stop @stop = true @thread.kill log.debug event: 'discover stopped' return state end |