Class: Zoology::PathCache

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/zoology/path_cache.rb,
lib/zoology/path_cache/watcher.rb

Defined Under Namespace

Classes: Watcher

Instance Method Summary collapse

Methods included from Logging

disable!, #logger, logger

Constructor Details

#initialize(client, path, &callback) ⇒ PathCache

Returns a new instance of PathCache.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/zoology/path_cache.rb', line 7

def initialize(client, path, &callback)
  @client   = client
  @watches  = {}
  @watcher  = nil
  @path     = path
  @callback = callback
  @client.on_connected do |_event|
    if @sleep
      logger.debug "Sleeping for #{@sleep}s to avoid thundering herd"
      sleep(@sleep) if @sleep
    end
    watch_paths
  end
  @client.on_expired do |_event|
    @watches.each { |_path, watcher| watcher.shutdown }
    @watches = {}
    @sleep   = rand(10)
  end
  if @client.connected?
    watch_paths
  end
end