Class: Entrance::Watcher::Agent
- Inherits:
-
Object
- Object
- Entrance::Watcher::Agent
- Defined in:
- lib/entrance/watcher/agent.rb
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
Instance Method Summary collapse
-
#initialize(path = "/doorkeepr/publish", params = {}) ⇒ Agent
constructor
A new instance of Agent.
- #reconfigure! ⇒ Object
- #services ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(path = "/doorkeepr/publish", params = {}) ⇒ Agent
Returns a new instance of Agent.
12 13 14 15 16 |
# File 'lib/entrance/watcher/agent.rb', line 12 def initialize path="/doorkeepr/publish",params={} @config = Synapse::Easy::Service.new params.merge(path:path) @watcher = Synapse::ZookeeperWatcher.new @config, self @scanner = ZK.new @config.hosts.first end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
11 12 13 |
# File 'lib/entrance/watcher/agent.rb', line 11 def callback @callback end |
Instance Method Details
#reconfigure! ⇒ Object
38 39 40 |
# File 'lib/entrance/watcher/agent.rb', line 38 def reconfigure! callback.call(self) end |
#services ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/entrance/watcher/agent.rb', line 26 def services @scanner.children(@config.path).map do |child| path = Pathname.new(@config.path).join(child).to_s service_data = JSON.parse(@scanner.get(path).first).with_indifferent_access server = OpenStruct.new service_data url = "http://#{server.host}:#{server.port}/doorkeepr" response = Unirest.get(url) announcement_data = response.body.with_indifferent_access announcement_data = announcement_data[:doorkeepr] if announcement_data[:doorkeepr] yield OpenStruct.new announcement_data end end |
#start ⇒ Object
17 18 19 20 21 22 |
# File 'lib/entrance/watcher/agent.rb', line 17 def start stop @thread=Thread.new do @watcher.start end end |
#stop ⇒ Object
23 24 25 |
# File 'lib/entrance/watcher/agent.rb', line 23 def stop @thread.kill if @thread end |