cellect-client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cellect/client.rb +8 -4
- data/lib/cellect/client/node_set.rb +1 -1
- data/lib/cellect/client/railtie.rb +37 -0
- data/lib/cellect/node_set.rb +3 -2
- data/lib/cellect/testing.rb +17 -0
- data/lib/cellect/version.rb +1 -1
- data/spec/client/connection_spec.rb +3 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cd2bca44b019223a6da43db439f1cf5cb5650c7
|
4
|
+
data.tar.gz: f2e7e6cd755aba1f96c734e7396507a0c910ec34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8501160197b8cd42a6293ef475f4050148b5db6cf28936185a0564cfa494f1c51d4341dcf913e3be0805b88119afe8909df8100af91dc117bd7a02e184ccfae9
|
7
|
+
data.tar.gz: 32a8a91403d0a50309e6de27be1ad68e299d1697d2becaa2b48cca2d1c0c9a3240c6529efee363f4141a164b58ff024771633266df76cfe2856e4885d3823604
|
data/lib/cellect/client.rb
CHANGED
@@ -9,8 +9,8 @@ module Cellect
|
|
9
9
|
attr_accessor :connection, :_node_set
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.node_set
|
13
|
-
self._node_set ||= NodeSet.supervise
|
12
|
+
def self.node_set(zk_url=nil)
|
13
|
+
self._node_set ||= NodeSet.supervise(zk_url)
|
14
14
|
_node_set.actors.first
|
15
15
|
end
|
16
16
|
|
@@ -22,7 +22,11 @@ module Cellect
|
|
22
22
|
node_set.nodes.values.sample
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
if defined?(::Rails)
|
26
|
+
require 'cellect/client/railtie'
|
27
|
+
else
|
28
|
+
Client.node_set
|
29
|
+
Client.connection = Connection.pool size: ENV.fetch('CELLECT_POOL_SIZE', 100).to_i
|
30
|
+
end
|
27
31
|
end
|
28
32
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Cellect
|
2
|
+
module Client
|
3
|
+
class ConfigurationError < StandardError; end;
|
4
|
+
|
5
|
+
class CellectRailtie < Rails::Railtie
|
6
|
+
initializer 'cellect.connect_to_zookeeper' do
|
7
|
+
ensure_config_file
|
8
|
+
config = YAML.load_file config_file
|
9
|
+
ensure_config_environment config
|
10
|
+
config = config[Rails.env].symbolize_keys
|
11
|
+
ensure_config_url config
|
12
|
+
|
13
|
+
Client.node_set config[:zk_url]
|
14
|
+
Client.connection = Connection.pool size: config.fetch(:pool_size, 100)
|
15
|
+
end
|
16
|
+
|
17
|
+
def config_file
|
18
|
+
Rails.root.join 'config/cellect.yml'
|
19
|
+
end
|
20
|
+
|
21
|
+
def ensure_config_file
|
22
|
+
return if File.exists?(config_file)
|
23
|
+
raise ConfigurationError.new "No configuration file found. Create config/cellect.yml first"
|
24
|
+
end
|
25
|
+
|
26
|
+
def ensure_config_environment(yaml)
|
27
|
+
return if yaml[Rails.env].is_a?(Hash)
|
28
|
+
raise ConfigurationError.new "No configuration for #{ Rails.env } found"
|
29
|
+
end
|
30
|
+
|
31
|
+
def ensure_config_url(hash)
|
32
|
+
return if hash[:zk_url].present?
|
33
|
+
raise ConfigurationError.new "No Zookeeper URL provided for #{ Rails.env } environment"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/cellect/node_set.rb
CHANGED
@@ -7,7 +7,8 @@ module Cellect
|
|
7
7
|
|
8
8
|
attr_accessor :zk, :state
|
9
9
|
|
10
|
-
def initialize
|
10
|
+
def initialize(zk_url = nil)
|
11
|
+
@zk_url = zk_url
|
11
12
|
self.state = :initializing
|
12
13
|
after(0.001){ async.initialize_zk } # don't block waiting for ZK to connect
|
13
14
|
end
|
@@ -28,7 +29,7 @@ module Cellect
|
|
28
29
|
protected
|
29
30
|
|
30
31
|
def zk_url
|
31
|
-
ENV.fetch
|
32
|
+
@zk_url || ENV.fetch('ZK_URL', 'localhost:2181')
|
32
33
|
end
|
33
34
|
|
34
35
|
def setup
|
data/lib/cellect/version.rb
CHANGED
@@ -62,10 +62,10 @@ module Cellect::Client
|
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'should get subjects' do
|
65
|
-
should_send action: :get, url: 'workflows/random?user_id=1&limit=10
|
66
|
-
connection.get_subjects host: 1, workflow_id: 'random', user_id: 1, limit: 10, group_id: 1
|
65
|
+
should_send action: :get, url: 'workflows/random?user_id=1&group_id=1&limit=10', to: 1
|
66
|
+
connection.get_subjects host: '1', workflow_id: 'random', user_id: 1, limit: 10, group_id: 1
|
67
67
|
should_send action: :get, url: 'workflows/random?user_id=1', to: 1
|
68
|
-
connection.get_subjects host: 1, workflow_id: 'random', user_id: 1
|
68
|
+
connection.get_subjects host: '1', workflow_id: 'random', user_id: 1
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cellect-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Parrish
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -169,7 +169,9 @@ files:
|
|
169
169
|
- lib/cellect/client.rb
|
170
170
|
- lib/cellect/client/connection.rb
|
171
171
|
- lib/cellect/client/node_set.rb
|
172
|
+
- lib/cellect/client/railtie.rb
|
172
173
|
- lib/cellect/node_set.rb
|
174
|
+
- lib/cellect/testing.rb
|
173
175
|
- lib/cellect/version.rb
|
174
176
|
- log/.gitkeep
|
175
177
|
- spec/client/connection_spec.rb
|