instructure_registrar 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/instructure_registrar/client.rb +21 -1
- data/lib/instructure_registrar/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5014c511426370b1e307bae148c02a4bae3066f5
|
4
|
+
data.tar.gz: 1109145f1f76673ce160c54cf77231c25ecced80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 217ecd296dd5ae1d84338cd41f8c7b6130baafb00ba5e2f9966dc647f48e9787b7866d2a1cb2e2eb51e7e55b4a4a7ec3d9a2cb6565cdacd68657b8d804faa79f
|
7
|
+
data.tar.gz: 475366f301ba26f164da32f544b301d1ea10211813c29a00deb4e30e8b4bdec4b985735a209a767ca60066cc3a666114782238babb87f14becba65499c32547a
|
@@ -3,6 +3,20 @@ module InstructureRegistrar
|
|
3
3
|
|
4
4
|
require 'etcd'
|
5
5
|
|
6
|
+
attr_reader :server_available
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@server_available = healthcheck
|
10
|
+
end
|
11
|
+
|
12
|
+
def healthcheck
|
13
|
+
begin
|
14
|
+
client.version
|
15
|
+
rescue
|
16
|
+
false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
6
20
|
def lookup(service_name)
|
7
21
|
begin
|
8
22
|
client.get("/#{service_name}").value
|
@@ -12,6 +26,7 @@ module InstructureRegistrar
|
|
12
26
|
end
|
13
27
|
|
14
28
|
def register
|
29
|
+
return unless server_available
|
15
30
|
client.set(
|
16
31
|
"/#{InstructureRegistrar.config.service_name}",
|
17
32
|
value: "#{InstructureRegistrar.config.service_host}:#{InstructureRegistrar.config.service_port}"
|
@@ -19,7 +34,12 @@ module InstructureRegistrar
|
|
19
34
|
end
|
20
35
|
|
21
36
|
def unregister
|
22
|
-
|
37
|
+
return unless server_available
|
38
|
+
begin
|
39
|
+
client.delete("/#{InstructureRegistrar.config.service_name}")
|
40
|
+
rescue Etcd::KeyNotFound
|
41
|
+
false
|
42
|
+
end
|
23
43
|
end
|
24
44
|
|
25
45
|
private
|