dryad 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a98ce3f592db4619f50c3dd4771e518324abc821ae9018d5665d6df4f078a9af
4
- data.tar.gz: dc808997b9151794e8ead44303b536ef7dfbf9b706e7615f14d563e9f3d6d833
3
+ metadata.gz: 1a83e68f41991b705835ebd2eeff92195fe239f58f484c0dbca1b0d68d85e11d
4
+ data.tar.gz: 187949a949a2b33bc6f53f5617f1d81b2cec60005240cab2a261a62de7103e0c
5
5
  SHA512:
6
- metadata.gz: 33b78afb03003071970a9f96c60bfeab3e62d03cddf1fc7941b04cc8c7c1f032b5ea7a92808508fef62ce3c4b6c20fa3bb7cb93734249c852f7d30436feb3868
7
- data.tar.gz: 298c46a4917aac6a2edf5fcdd060c3183a33eabc37058dc34e6903fc36466e61a8f5a03281d2dcc92fa8ef4e57b27c5096f7aa6590e1be31dddb20a9cda6ba9d
6
+ metadata.gz: 0d2570f9c228eb72688d2142973d040b32fc578c11f0a777a4f2482bcfe3c15c1ed33da03240714ef7799f6ddb5c704d61d2f676c6b54e2e7f1ec68b7b486a18
7
+ data.tar.gz: aa3d81845defb3b26c1e1bda3442565dfca6a4f5ac2552628c5952bbc531ebae9ac242279c192c516d61d04b280c8c7cbe6fae9cd1fce6356c449f8f00569359
data/Gemfile.lock CHANGED
@@ -1,19 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dryad (1.0.0)
5
- dryad-cluster (= 1.0.0)
6
- dryad-consul (= 1.0.0)
7
- dryad-core (= 1.0.0)
8
- dryad-cluster (1.0.0)
4
+ dryad (1.0.1)
5
+ dryad-cluster (= 1.0.1)
6
+ dryad-consul (= 1.0.1)
7
+ dryad-core (= 1.0.1)
8
+ dryad-cluster (1.0.1)
9
9
  concurrent-ruby (~> 1.1, >= 1.1.5)
10
- dryad-consul (= 1.0.0)
11
- dryad-core (= 1.0.0)
12
- dryad-consul (1.0.0)
10
+ dryad-consul (= 1.0.1)
11
+ dryad-core (= 1.0.1)
12
+ dryad-consul (1.0.1)
13
13
  concurrent-ruby (~> 1.1, >= 1.1.5)
14
14
  diplomat (~> 2.2, >= 2.2.4)
15
- dryad-core (= 1.0.0)
16
- dryad-core (1.0.0)
15
+ dryad-core (= 1.0.1)
16
+ dryad-core (1.0.1)
17
17
 
18
18
  GEM
19
19
  remote: https://rubygems.org/
data/lib/dryad/railtie.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "rails"
2
+ require "dryad"
2
3
 
3
4
  module Dryad
4
5
  class Railtie < Rails::Railtie
@@ -11,4 +12,50 @@ module Dryad
11
12
  end
12
13
  end
13
14
  ActiveSupport.run_load_hooks(:dryad, Core)
15
+
16
+ module Consul
17
+ class DBConfigObserver < ConfigObserver
18
+ def update_self(config_desc)
19
+ ActiveRecord::Base.configurations = YAML.load(ERB.new(config_desc.payload).result)
20
+ ActiveRecord::Base.establish_connection(Rails.env.to_sym)
21
+ end
22
+ end
23
+
24
+ class Railtie < ::Rails::Railtie
25
+ initializer "dryad_consul.set_consul" do
26
+ ActiveSupport.on_load(:dryad_consul) do
27
+ Dryad::Consul.configure_consul(Dryad.configuration)
28
+ end
29
+ end
30
+
31
+ initializer "dryad_consul.update_active_record_connection" do
32
+ config.after_initialize do
33
+ db_path = "#{Dryad.configuration.namespace}/#{Dryad.configuration.group}/database.yml"
34
+ observer = ::Dryad::Consul::DBConfigObserver.new
35
+ begin
36
+ db_config = Dryad::Consul::ConfigProvider.instance.load(db_path, observer)
37
+ raise Dryad::Core::ConfigurationNotFound, db_path if db_config.nil?
38
+ ActiveRecord::Base.configurations = YAML.load(ERB.new(db_config.payload).result)
39
+ ActiveRecord::Base.establish_connection(Rails.env.to_sym)
40
+ rescue Dryad::Core::ConfigurationNotFound => e
41
+ raise e
42
+ rescue Exception => e
43
+ Rails.logger.warn e.message
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ ActiveSupport.run_load_hooks(:dryad_consul, Consul)
50
+
51
+ module Cluster
52
+ class Railtie < Rails::Railtie
53
+ initializer "dryad_cluster.set_config" do
54
+ ActiveSupport.on_load(:dryad_cluster) do
55
+ Dryad::Cluster.configuration = Dryad.configuration
56
+ end
57
+ end
58
+ end
59
+ end
60
+ ActiveSupport.run_load_hooks(:dryad_cluster, Cluster)
14
61
  end
data/lib/dryad/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dryad
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
data/lib/dryad.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require "dryad/version"
2
2
  require "dryad/configuration"
3
3
  require "dryad/core"
4
- require "dryad/railtie" if defined?(Rails)
5
4
  require "dryad/consul"
6
5
  require "dryad/cluster"
6
+ require "dryad/railtie" if defined?(Rails)
7
7
 
8
8
  module Dryad
9
9
  class << self
@@ -36,5 +36,14 @@ module Dryad
36
36
  rescue => e
37
37
  raise e, "Cannot load dryad configuration:\n#{e.message}", e.backtrace
38
38
  end
39
+
40
+ def register_services
41
+ service = Dryad::Consul.build_service(
42
+ Dryad.configuration.namespace,
43
+ Dryad.configuration.group,
44
+ Dryad.configuration.service
45
+ )
46
+ Dryad::Consul::ServiceRegistry.instance.register(service)
47
+ end
39
48
  end
40
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dryad
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
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-07-09 00:00:00.000000000 Z
11
+ date: 2019-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dryad-core
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0
19
+ version: 1.0.1
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: 1.0.0
26
+ version: 1.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dryad-consul
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.0
33
+ version: 1.0.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 1.0.0
40
+ version: 1.0.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dryad-cluster
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 1.0.0
47
+ version: 1.0.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 1.0.0
54
+ version: 1.0.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement