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 |
# File 'lib/instructure_registrar/client.rb', line 19 def lookup(service_name) begin client.get("/#{service_name}").value rescue Etcd::KeyNotFound "unknown" end end |
#register ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/instructure_registrar/client.rb', line 27 def register return unless server_available InstructureRegistrar.config.service_config.keys.each do |key| p "InstructureRegistrar setting #{InstructureRegistrar.config.service_name}/#{key} on #{InstructureRegistrar.config.registry_host}..." client.set( "/#{InstructureRegistrar.config.service_name}/#{key}", value: InstructureRegistrar.config.service_config[key] ) end end |
#unregister ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/instructure_registrar/client.rb', line 38 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 |