dryad-consul 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -3
- data/dryad-consul.gemspec +1 -0
- data/lib/dryad/consul/config_observer.rb +24 -0
- data/lib/dryad/consul/config_provider.rb +36 -6
- data/lib/dryad/consul/railtie.rb +11 -2
- data/lib/dryad/consul/version.rb +1 -1
- data/lib/dryad/consul.rb +1 -0
- metadata +25 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebfad19cea21ae94dd248931ed5a37afbdd59f60ec9a65902b33c77c3bd9ffad
|
4
|
+
data.tar.gz: 42de2e60a31f501314c04adc676720f10eac9f23499efcaf4b0b59eaf6713d18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ac0341de021e32e7e7cedd25412a0c108c02fb085ca20c9c05bc28cd43f5c68a034ca018e2927fc1dd64e44c0b6b673a27ac62adf2725199328cb07246e9054
|
7
|
+
data.tar.gz: bb233a9b8c98588d0fa00fb9d17f1b103ab62e0a22b16ab346811eee1d6554174dbbf8bf1d57e2c2b8cb186f346d291cbdc378e78ab9728a6a27c5ee56d5788c
|
data/Gemfile.lock
CHANGED
@@ -1,19 +1,21 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dryad-consul (0.
|
4
|
+
dryad-consul (0.3.0)
|
5
|
+
concurrent-ruby (~> 1.1, >= 1.1.5)
|
5
6
|
diplomat (~> 2.2, >= 2.2.4)
|
6
|
-
dryad-core (= 0.
|
7
|
+
dryad-core (= 0.3.0)
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
10
11
|
specs:
|
12
|
+
concurrent-ruby (1.1.5)
|
11
13
|
deep_merge (1.2.1)
|
12
14
|
diff-lcs (1.3)
|
13
15
|
diplomat (2.2.5)
|
14
16
|
deep_merge (~> 1.0, >= 1.0.1)
|
15
17
|
faraday (~> 0.9)
|
16
|
-
dryad-core (0.
|
18
|
+
dryad-core (0.3.0)
|
17
19
|
faraday (0.15.4)
|
18
20
|
multipart-post (>= 1.2, < 3)
|
19
21
|
multipart-post (2.1.1)
|
data/dryad-consul.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_dependency "dryad-core", Dryad::Consul::VERSION
|
25
25
|
spec.add_dependency "diplomat", "~> 2.2", ">= 2.2.4"
|
26
|
+
spec.add_dependency "concurrent-ruby", "~> 1.1", ">= 1.1.5"
|
26
27
|
|
27
28
|
spec.add_development_dependency "bundler", "~> 2.0"
|
28
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Dryad
|
2
|
+
module Consul
|
3
|
+
class ConfigObserver < ::Dryad::Core::Observer
|
4
|
+
def initialize
|
5
|
+
@last_version = 0
|
6
|
+
end
|
7
|
+
|
8
|
+
def update(time, config_desc, exception)
|
9
|
+
if exception
|
10
|
+
puts "(#{time}) [#{self.class.to_s}] #{exception.message}"
|
11
|
+
elsif config_desc
|
12
|
+
if @last_version < config_desc.version
|
13
|
+
update_self(config_desc)
|
14
|
+
@last_version = config_desc.version
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def update_self(config_desc)
|
20
|
+
raise "Implement this method"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,13 +1,43 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'concurrent'
|
3
|
+
|
1
4
|
module Dryad
|
2
5
|
module Consul
|
3
6
|
class ConfigProvider < Dryad::Core::ConfigProvider
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
include Singleton
|
8
|
+
WATCHER_EXECUTION_INTERVAL = 5 * 60
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@timers = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def load(path, observer = nil)
|
15
|
+
config = Dryad::Consul::KeyValueClient.get(path)
|
16
|
+
if config.nil?
|
17
|
+
nil
|
18
|
+
else
|
19
|
+
add_observer(observer, path)
|
20
|
+
Dryad::Core::ConfigDesc.new(path, config.Value, config.ModifyIndex)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def add_observer(observer, path)
|
26
|
+
if observer && observer.is_a?(Dryad::Core::Observer)
|
27
|
+
if @timers.has_key?(path)
|
28
|
+
@timers[path].add_observer(observer)
|
9
29
|
else
|
10
|
-
|
30
|
+
timer = Concurrent::TimerTask.new(execution_interval: WATCHER_EXECUTION_INTERVAL) do
|
31
|
+
config = Dryad::Consul::KeyValueClient.get(path)
|
32
|
+
if config.nil?
|
33
|
+
nil
|
34
|
+
else
|
35
|
+
Dryad::Core::ConfigDesc.new(path, config.Value, config.ModifyIndex)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
timer.add_observer(observer)
|
39
|
+
timer.execute
|
40
|
+
@timers[path] = timer
|
11
41
|
end
|
12
42
|
end
|
13
43
|
end
|
data/lib/dryad/consul/railtie.rb
CHANGED
@@ -3,7 +3,14 @@ require "dryad"
|
|
3
3
|
|
4
4
|
module Dryad
|
5
5
|
module Consul
|
6
|
-
class
|
6
|
+
class DBConfigObserver < ConfigObserver
|
7
|
+
def update_self(config_desc)
|
8
|
+
ActiveRecord::Base.configurations = YAML.load(ERB.new(config_desc.payload).result)
|
9
|
+
ActiveRecord::Base.establish_connection(Rails.env.to_sym)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Railtie < ::Rails::Railtie
|
7
14
|
initializer "dryad_consul.set_consul" do
|
8
15
|
ActiveSupport.on_load(:dryad_consul) do
|
9
16
|
Dryad::Consul.configure_consul(Dryad.configuration)
|
@@ -13,8 +20,10 @@ module Dryad
|
|
13
20
|
initializer "dryad_consul.update_active_record_connection" do
|
14
21
|
config.after_initialize do
|
15
22
|
db_path = "#{Dryad.configuration.namespace}/#{Dryad.configuration.group}/database.yml"
|
23
|
+
observer = ::Dryad::Consul::DBConfigObserver.new
|
16
24
|
begin
|
17
|
-
db_config = Dryad::Consul::ConfigProvider.load(db_path)
|
25
|
+
db_config = Dryad::Consul::ConfigProvider.instance.load(db_path, observer)
|
26
|
+
raise Dryad::Core::ConfigurationNotFound, db_path
|
18
27
|
ActiveRecord::Base.configurations = YAML.load(ERB.new(db_config.payload).result)
|
19
28
|
ActiveRecord::Base.establish_connection(Rails.env.to_sym)
|
20
29
|
rescue Dryad::Core::ConfigurationNotFound => e
|
data/lib/dryad/consul/version.rb
CHANGED
data/lib/dryad/consul.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dryad-consul
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pan Jie
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dryad-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.3.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.3.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: diplomat
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,6 +44,26 @@ dependencies:
|
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 2.2.4
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: concurrent-ruby
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.1'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.1.5
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '1.1'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.1.5
|
47
67
|
- !ruby/object:Gem::Dependency
|
48
68
|
name: bundler
|
49
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,6 +124,7 @@ files:
|
|
104
124
|
- bin/setup
|
105
125
|
- dryad-consul.gemspec
|
106
126
|
- lib/dryad/consul.rb
|
127
|
+
- lib/dryad/consul/config_observer.rb
|
107
128
|
- lib/dryad/consul/config_provider.rb
|
108
129
|
- lib/dryad/consul/key_value_client.rb
|
109
130
|
- lib/dryad/consul/railtie.rb
|