rails_failover 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/lib/rails_failover/active_record.rb +1 -2
- data/lib/rails_failover/active_record/handler.rb +10 -3
- data/lib/rails_failover/active_record/middleware.rb +6 -1
- data/lib/rails_failover/active_record/railtie.rb +7 -2
- data/lib/rails_failover/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6568f67088bad641f6ca7c96f477713d59baeee1992b2acba1e6db9568d55cce
|
4
|
+
data.tar.gz: 3978f5d594cb5efb953d937bd95a9e8778ec2c1caa0b35903889e246b55c872a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dae66bec185b1254788bcd3ef7a60c638105077803358408a3275cd7f5fa6e928706e525c7cf3f9f051e74241e5ee0da9e5e390729fc4b7c624fb4f2f23a5b26
|
7
|
+
data.tar.gz: cfc083e71f1514cdb7a884693cb077c09bf28372a46ee9fd51eab45bfbb4528a0909f67ae2be434c0ba51761562e8cfe06c3ecf251259c7ec83c44a302ab5d77
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.7.3] - 2021-04-15
|
10
|
+
|
11
|
+
- FEATURE: Compatibility with Rails 6.1
|
12
|
+
|
13
|
+
## [0.7.2] - 2021-04-14
|
14
|
+
|
15
|
+
No changes.
|
16
|
+
|
17
|
+
## [0.7.1] - 2021-04-14
|
18
|
+
|
19
|
+
- FIX: Backward compatability with Rails 6.0
|
20
|
+
|
21
|
+
## [0.7.0] - 2021-04-14
|
22
|
+
|
23
|
+
- FEATURE: Partial compatibility with Rails 6.1
|
24
|
+
|
9
25
|
## [0.6.5] - 2020-12-16
|
10
26
|
|
11
27
|
- FIX: Catch exceptions that are not intercepted by `ActionDispatch::DebugExceptions`.
|
@@ -27,8 +27,7 @@ module RailsFailover
|
|
27
27
|
@verify_primary_frequency_seconds || 5
|
28
28
|
end
|
29
29
|
|
30
|
-
def self.establish_reading_connection(handler,
|
31
|
-
config = connection_spec.config
|
30
|
+
def self.establish_reading_connection(handler, config)
|
32
31
|
|
33
32
|
if config[:replica_host] && config[:replica_port]
|
34
33
|
replica_config = config.dup
|
@@ -56,13 +56,20 @@ module RailsFailover
|
|
56
56
|
|
57
57
|
primaries_down.keys.each do |handler_key|
|
58
58
|
connection_handler = ::ActiveRecord::Base.connection_handlers[handler_key]
|
59
|
-
|
60
|
-
|
59
|
+
|
60
|
+
connection_pool = connection_handler.retrieve_connection_pool(spec_name)
|
61
|
+
if connection_pool.respond_to?(:db_config)
|
62
|
+
config = connection_pool.db_config.configuration_hash
|
63
|
+
adapter_method = connection_pool.db_config.adapter_method
|
64
|
+
else
|
65
|
+
config = connection_pool.spec.config
|
66
|
+
adapter_method = connection_pool.spec.adapter_method
|
67
|
+
end
|
61
68
|
logger.debug "#{Process.pid} Checking server for '#{handler_key} #{spec_name}'..."
|
62
69
|
connection_active = false
|
63
70
|
|
64
71
|
begin
|
65
|
-
connection = ::ActiveRecord::Base.public_send(
|
72
|
+
connection = ::ActiveRecord::Base.public_send(adapter_method, config)
|
66
73
|
connection_active = connection.active?
|
67
74
|
rescue => e
|
68
75
|
logger.debug "#{Process.pid} Connection to server for '#{handler_key} #{spec_name}' failed with '#{e.message}'"
|
@@ -80,7 +80,12 @@ module RailsFailover
|
|
80
80
|
handler = ::ActiveRecord::ConnectionAdapters::ConnectionHandler.new
|
81
81
|
|
82
82
|
::ActiveRecord::Base.connection_handlers[writing_role].connection_pools.each do |pool|
|
83
|
-
|
83
|
+
if pool.respond_to?(:db_config)
|
84
|
+
config = pool.db_config.configuration_hash
|
85
|
+
else
|
86
|
+
config = pool.spec.config
|
87
|
+
end
|
88
|
+
::RailsFailover::ActiveRecord.establish_reading_connection(handler, config)
|
84
89
|
end
|
85
90
|
|
86
91
|
handler
|
@@ -27,9 +27,14 @@ module RailsFailover
|
|
27
27
|
::ActiveRecord::ConnectionAdapters::ConnectionHandler.new
|
28
28
|
|
29
29
|
::ActiveRecord::Base.connection_handlers[::ActiveRecord::Base.writing_role].connection_pools.each do |connection_pool|
|
30
|
+
if connection_pool.respond_to?(:db_config)
|
31
|
+
config = connection_pool.db_config.configuration_hash
|
32
|
+
else
|
33
|
+
config = connection_pool.spec.config
|
34
|
+
end
|
30
35
|
RailsFailover::ActiveRecord.establish_reading_connection(
|
31
36
|
::ActiveRecord::Base.connection_handlers[::ActiveRecord::Base.reading_role],
|
32
|
-
|
37
|
+
config
|
33
38
|
)
|
34
39
|
end
|
35
40
|
|
@@ -37,7 +42,7 @@ module RailsFailover
|
|
37
42
|
::ActiveRecord::Base.connection
|
38
43
|
rescue ::ActiveRecord::NoDatabaseError
|
39
44
|
# Do nothing since database hasn't been created
|
40
|
-
rescue ::PG::Error
|
45
|
+
rescue ::PG::Error, ::ActiveRecord::ConnectionNotEstablished
|
41
46
|
Handler.instance.verify_primary(::ActiveRecord::Base.writing_role)
|
42
47
|
::ActiveRecord::Base.connection_handler = ::ActiveRecord::Base.lookup_connection_handler(:reading)
|
43
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_failover
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alan Tan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|