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 68 69 70 |
# File 'lib/franz/discover.rb', line 20 def initialize opts={} @configs = opts[:configs] || [] @discoveries = opts[:discoveries] || [] @deletions = opts[:deletions] || [] @discover_interval = opts[:discover_interval] || 30 @ignore_before = opts[:ignore_before] || 0 @known = opts[:known] || [] @logger = opts[:logger] || Logger.new(STDOUT) @known = Set.new(@known) @configs = 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', configs: configs, discoveries: discoveries, deletions: deletions, discover_interval: discover_interval, ignore_before: ignore_before, opts: opts end |
Instance Method Details
#state ⇒ Object
Return the internal “known” state
84 85 86 |
# File 'lib/franz/discover.rb', line 84 def state return @known.to_a end |
#stop ⇒ Array
Stop the Discover thread. Effectively only once.
75 76 77 78 79 80 81 |
# File 'lib/franz/discover.rb', line 75 def stop return state if @stop @stop = true @thread.kill log.debug event: 'discover stopped' return state end |