rails_failover 0.7.2 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d891800bc3c474ab5d6bb2f9c9de5143b282e0d8bca7abaaf7e961ecc0de5d2b
4
- data.tar.gz: 6ae3d0e02913ab900e6cc4428a6c07e7ccea9e5d61325ae51d807d3ddeae0106
3
+ metadata.gz: 6568f67088bad641f6ca7c96f477713d59baeee1992b2acba1e6db9568d55cce
4
+ data.tar.gz: 3978f5d594cb5efb953d937bd95a9e8778ec2c1caa0b35903889e246b55c872a
5
5
  SHA512:
6
- metadata.gz: 56267ae5f7529d55fd1612f5e6af3e922f0930bc06416783df658aa94edafc0a6e79053097668f22fe715964fc54c9636c785bb9b6476bbcdd36cd5e8bd0994a
7
- data.tar.gz: 05203aaec3c90fbc314bf91ed8b60a9269b88597e74e665ebdad4a9341f2cc109be81dfb3adaec2bcc356fc34180235cb8d7d0e3e39a3db3cd088d6601f17907
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, connection_spec)
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
- spec = connection_handler.retrieve_connection_pool(spec_name).spec
60
- config = spec.config
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(spec.adapter_method, config)
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
- ::RailsFailover::ActiveRecord.establish_reading_connection(handler, pool.spec)
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
- connection_pool.spec
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsFailover
4
- VERSION = "0.7.2"
4
+ VERSION = "0.7.3"
5
5
  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.2
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-14 00:00:00.000000000 Z
11
+ date: 2021-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord