Class: InstructureRegistrar::Client
- Inherits:
-
Object
- Object
- InstructureRegistrar::Client
- Defined in:
- lib/instructure_registrar/client.rb
Instance Attribute Summary collapse
-
#server_available ⇒ Object
readonly
Returns the value of attribute server_available.
Instance Method Summary collapse
- #healthcheck ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #lookup(service_name) ⇒ Object
- #register ⇒ Object
- #unregister ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/instructure_registrar/client.rb', line 8 def initialize @server_available = healthcheck end |
Instance Attribute Details
#server_available ⇒ Object (readonly)
Returns the value of attribute server_available.
6 7 8 |
# File 'lib/instructure_registrar/client.rb', line 6 def server_available @server_available end |
Instance Method Details
#healthcheck ⇒ Object
12 13 14 15 16 17 |
# File 'lib/instructure_registrar/client.rb', line 12 def healthcheck client.version rescue p "WARNING: etcd server unavailable at #{InstructureRegistrar.config.registry_host}:#{InstructureRegistrar.config.registry_port}" false end |
#lookup(service_name) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/instructure_registrar/client.rb', line 19 def lookup(service_name) begin client.get("/#{service_name}").children.inject({}) do |h, child| h["#{child.key.split('/').last}"] = child.value; h end rescue Etcd::KeyNotFound {status: "unknown"} end end |
#register ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/instructure_registrar/client.rb', line 29 def register return unless server_available InstructureRegistrar.config.service_config.keys.each do |key| client.set( "/#{InstructureRegistrar.config.service_name}/#{key}", value: InstructureRegistrar.config.service_config[key] ) end end |
#unregister ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/instructure_registrar/client.rb', line 39 def unregister return unless server_available begin InstructureRegistrar.config.service_config.keys.each do |key| client.delete( "/#{InstructureRegistrar.config.service_name}/#{key}", value: InstructureRegistrar.config.service_config[key] ) end rescue Etcd::KeyNotFound false end end |