zoo-service-discovery 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +9 -9
- data/lib/zoo_service/publication.rb +13 -4
- data/spec/features/discovery_spec.rb +12 -2
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzIwMThkMjJlOTZiODViMzAwNzNjYzM1ZjI5YTk3Y2UxYzhjODczNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
7
|
-
|
6
|
+
OTVhNjZkOGMxNmVmMDcxZjhmY2ZlOGRhMTE4YTlkOTEwMmJlNTZiOQ==
|
7
|
+
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Yjc3Y2MyN2IyMTY2ZWZhYzE2NmIzYzQ5ODg1NDQzYmIyYzM2YjY1YWYzYzlj
|
10
|
+
YTRhMmY4MjViYjkyOGIyZGM0MTY0YzZiOTk3MDcwNWU2ZjI1MmQyNmY4MjUx
|
11
|
+
OWMyNzEzMmU3NzFhYjZjYjRkOTViNWM2YmY3NTE3YTQzOTMzYmU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Zjg2OWMzMjExYzk3ZDc2NjA2ZTAwMGM1ZDg3MDYwZDE0NGJhNTE2ZDNiM2Vi
|
14
|
+
OWMwMWJkN2E1NTk3OGMzZjMxYTk0YjdkZGMxODc0YTBjNTM5NGQ1NzI2ZjI4
|
15
|
+
ODVlNjYyMWE5MzIzZGExOGU5OTFiMWQ0ZjYxNTUyYzZiMWQ5NDk=
|
@@ -23,10 +23,19 @@ module ZooService
|
|
23
23
|
# Returns +true+, if everything went OK, +false+ otherwise.
|
24
24
|
def register_service(name, url)
|
25
25
|
registration_block = create_registration_block(name, url)
|
26
|
-
service_registration_blocks
|
26
|
+
service_registration_blocks[name.to_sym] = registration_block
|
27
27
|
registration_block.(zk)
|
28
28
|
end
|
29
29
|
|
30
|
+
# :call-seq:
|
31
|
+
# unregister_service(name) => Boolean
|
32
|
+
#
|
33
|
+
# Unregisters all the instances of a well-known service with _name_.
|
34
|
+
def unregister_service(name)
|
35
|
+
service_registration_blocks.delete(name.to_sym)
|
36
|
+
zk.rm_rf("/services/#{name}")
|
37
|
+
end
|
38
|
+
|
30
39
|
def reconnect
|
31
40
|
@zk = nil
|
32
41
|
zk
|
@@ -46,7 +55,7 @@ module ZooService
|
|
46
55
|
# Stores the registration blocks that are rerun after reconnection to
|
47
56
|
# the ZooKeeper.
|
48
57
|
def service_registration_blocks
|
49
|
-
@service_registration_blocks ||=
|
58
|
+
@service_registration_blocks ||= { }
|
50
59
|
end
|
51
60
|
|
52
61
|
# Returns a working instance of a ZooKeeper client.
|
@@ -54,7 +63,7 @@ module ZooService
|
|
54
63
|
@zk ||= ZK.new(ENV['SERVICE_DISCOVERY_WELLKNOWN_ADDRESS'] || 'localhost:2181') do |zk|
|
55
64
|
zk.on_connected do
|
56
65
|
# Rerun all the registrations upon reconnection
|
57
|
-
service_registration_blocks.each do |registration_block|
|
66
|
+
service_registration_blocks.values.each do |registration_block|
|
58
67
|
registration_block.(zk)
|
59
68
|
end
|
60
69
|
end
|
@@ -64,4 +73,4 @@ module ZooService
|
|
64
73
|
end
|
65
74
|
|
66
75
|
Publication = defined?(PhusionPassenger) ? PublicationImpl.new(PhusionPassenger) : PublicationImpl.new
|
67
|
-
end
|
76
|
+
end
|
@@ -12,8 +12,12 @@ describe "Discovered service URL" do
|
|
12
12
|
|
13
13
|
context "when service is registered" do
|
14
14
|
|
15
|
+
let(:publication) {
|
16
|
+
ZooService::PublicationImpl.new
|
17
|
+
}
|
18
|
+
|
15
19
|
let!(:service) {
|
16
|
-
|
20
|
+
publication.register_service("service", real_service_url)
|
17
21
|
"service"
|
18
22
|
}
|
19
23
|
|
@@ -25,6 +29,12 @@ describe "Discovered service URL" do
|
|
25
29
|
should == nil # check that it cannot be discovered
|
26
30
|
end
|
27
31
|
|
32
|
+
it "should be nil if we then unregister the service" do
|
33
|
+
sleep 0.5
|
34
|
+
publication.unregister_service(service)
|
35
|
+
should == nil
|
36
|
+
end
|
37
|
+
|
28
38
|
end
|
29
39
|
|
30
40
|
context "when service is not registered" do
|
@@ -37,4 +47,4 @@ describe "Discovered service URL" do
|
|
37
47
|
|
38
48
|
end
|
39
49
|
|
40
|
-
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zoo-service-discovery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Druzhinin <andrey.druginin@gmail.com>
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2014-02-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: zk
|
@@ -32,6 +32,7 @@ executables: []
|
|
32
32
|
extensions: []
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
|
+
- README.md
|
35
36
|
- lib/zoo-service-discovery.rb
|
36
37
|
- lib/zoo_service/discovery.rb
|
37
38
|
- lib/zoo_service/publication.rb
|
@@ -40,7 +41,6 @@ files:
|
|
40
41
|
- spec/features/passenger_spec.rb
|
41
42
|
- spec/spec_helper.rb
|
42
43
|
- spec/support/zookeeper_runner.rb
|
43
|
-
- README.md
|
44
44
|
homepage: http://uniqsystems.ru/
|
45
45
|
licenses: []
|
46
46
|
metadata: {}
|
@@ -60,9 +60,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
60
|
version: '0'
|
61
61
|
requirements: []
|
62
62
|
rubyforge_project:
|
63
|
-
rubygems_version: 2.
|
63
|
+
rubygems_version: 2.2.1
|
64
64
|
signing_key:
|
65
65
|
specification_version: 4
|
66
66
|
summary: ZooKeeper service discovery gem
|
67
67
|
test_files: []
|
68
|
-
has_rdoc:
|