rails_failover 0.6.5 → 0.8.1

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: 45afa97c24a3c8f4fac5c74a52eabbf0d06b9f7ad037a76b18bee05875b4f374
4
- data.tar.gz: e57ffc9182a9b2f4145c04d4f921bcd79aee3edfec5dedacac2fb6f23d39dc9d
3
+ metadata.gz: 9b0f3e010743d83bd67b2cce785fde0952ba32c82c8c1ab5fef3aa56e5baa520
4
+ data.tar.gz: 26cc2466069dfe48b691d8676078b3ed9ee3ce82e7a8d4447fa327436741fd39
5
5
  SHA512:
6
- metadata.gz: 0ee4ae4e79e17881a49f77711b5f13f301977d67cd177f8d16296cff93c0aea63b9151f235acfde87afaae14f6215840fbb3efb6024a98b59c14454b88705356
7
- data.tar.gz: 48d815e482d5b6b92316431bda654709f3049647292c4a4d9b8a6a075086be2e23b12cceed898d07e10f729bc85217aa395521a49ffd1c4baad63927ed938963
6
+ metadata.gz: 5ce28a0d758dde383537bce455502edfcbf9388ad4c2835edc17b2e259156affc885153f728e39fa66c8c25d3f9dfea34a8f489b663e7738fc092dc6c76dccb8
7
+ data.tar.gz: 0f0c08446e0e64c5eb6ee972e80e8776e58fbd32877254e50098a17a4d4475db64379d7ad237933b054e5eaf7c54df72785c69253e7d31be1b28d38028fcaf11
@@ -5,8 +5,7 @@ on:
5
5
  push:
6
6
  branches:
7
7
  - master
8
- tags:
9
- - v*
8
+ - main
10
9
 
11
10
  jobs:
12
11
  build:
@@ -18,22 +17,19 @@ jobs:
18
17
  strategy:
19
18
  fail-fast: false
20
19
  matrix:
21
- ruby:
22
- - 2.6
23
- - 2.7
24
- build_types: ["LINT", "REDIS", "ACTIVERECORD"]
25
- exclude:
26
- - ruby: 2.6
20
+ ruby: ["2.6", "2.7", "3.0", "3.1"]
21
+ build_types: ["REDIS", "ACTIVERECORD"]
22
+ include:
23
+ - ruby: "3.1"
27
24
  build_types: "LINT"
28
25
 
29
26
  steps:
30
- - uses: actions/checkout@v1
27
+ - uses: actions/checkout@v2
31
28
 
32
29
  - name: Setup ruby
33
- uses: actions/setup-ruby@v1
30
+ uses: ruby/setup-ruby@v1
34
31
  with:
35
32
  ruby-version: ${{ matrix.ruby }}
36
- architecture: 'x64'
37
33
 
38
34
  - name: Setup bundler
39
35
  run: gem install bundler
@@ -68,7 +64,7 @@ jobs:
68
64
  if: env.BUILD_TYPE == 'ACTIVERECORD'
69
65
 
70
66
  publish:
71
- if: contains(github.ref, 'refs/tags/v')
67
+ if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
72
68
  needs: build
73
69
  runs-on: ubuntu-latest
74
70
 
@@ -76,6 +72,8 @@ jobs:
76
72
  - uses: actions/checkout@v2
77
73
 
78
74
  - name: Release Gem
79
- uses: CvX/publish-rubygems-action@master
75
+ uses: discourse/publish-rubygems-action@v2
80
76
  env:
81
- RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
77
+ RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
78
+ GIT_EMAIL: team@discourse.org
79
+ GIT_NAME: discoursebot
data/.gitignore CHANGED
@@ -16,3 +16,4 @@
16
16
  *.rdb
17
17
 
18
18
  *.gem
19
+ Gemfile.lock
data/CHANGELOG.md CHANGED
@@ -6,6 +6,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.8.0] - 2022-01-17
10
+
11
+ - FEATURE: Compatibility with Rails 7.0+
12
+
13
+ ## [0.7.3] - 2021-04-15
14
+
15
+ - FEATURE: Compatibility with Rails 6.1
16
+
17
+ ## [0.7.2] - 2021-04-14
18
+
19
+ No changes.
20
+
21
+ ## [0.7.1] - 2021-04-14
22
+
23
+ - FIX: Backward compatability with Rails 6.0
24
+
25
+ ## [0.7.0] - 2021-04-14
26
+
27
+ - FEATURE: Partial compatibility with Rails 6.1
28
+
9
29
  ## [0.6.5] - 2020-12-16
10
30
 
11
31
  - FIX: Catch exceptions that are not intercepted by `ActionDispatch::DebugExceptions`.
data/README.md CHANGED
@@ -53,7 +53,7 @@ end
53
53
 
54
54
  #### Multiple connection handlers
55
55
 
56
- Note: This API is unstable and is likely to changes when Rails 6.1 is released with sharding support.
56
+ Note: This API is unstable and is likely to change when Rails 6.1 is released with sharding support.
57
57
 
58
58
  ```
59
59
  # config/database.yml
@@ -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
@@ -4,7 +4,15 @@ module RailsFailover
4
4
  module ActiveRecord
5
5
  class Railtie < ::Rails::Railtie
6
6
  initializer "rails_failover.init", after: "active_record.initialize_database" do |app|
7
- config = ::ActiveRecord::Base.connection_config
7
+
8
+ # AR 6.0 / 6.1 compat
9
+ config =
10
+ if ::ActiveRecord::Base.respond_to? :connection_db_config
11
+ ::ActiveRecord::Base.connection_db_config.configuration_hash
12
+ else
13
+ ::ActiveRecord::Base.connection_config
14
+ end
15
+
8
16
  app.config.active_record_rails_failover = false
9
17
 
10
18
  if !!(config[:replica_host] && config[:replica_port])
@@ -19,9 +27,14 @@ module RailsFailover
19
27
  ::ActiveRecord::ConnectionAdapters::ConnectionHandler.new
20
28
 
21
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
22
35
  RailsFailover::ActiveRecord.establish_reading_connection(
23
36
  ::ActiveRecord::Base.connection_handlers[::ActiveRecord::Base.reading_role],
24
- connection_pool.spec
37
+ config
25
38
  )
26
39
  end
27
40
 
@@ -29,7 +42,7 @@ module RailsFailover
29
42
  ::ActiveRecord::Base.connection
30
43
  rescue ::ActiveRecord::NoDatabaseError
31
44
  # Do nothing since database hasn't been created
32
- rescue ::PG::Error => e
45
+ rescue ::PG::Error, ::ActiveRecord::ConnectionNotEstablished
33
46
  Handler.instance.verify_primary(::ActiveRecord::Base.writing_role)
34
47
  ::ActiveRecord::Base.connection_handler = ::ActiveRecord::Base.lookup_connection_handler(:reading)
35
48
  end
@@ -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
@@ -169,7 +169,7 @@ module RailsFailover
169
169
  # Calling .disconnect can cause a running subscribe() to block forever
170
170
  # Therefore try to acquire the lock
171
171
  def soft_disconnect(redis, client, role)
172
- has_lock = redis.mon_try_enter
172
+ has_lock = redis_mon_try_enter(redis)
173
173
 
174
174
  if !has_lock
175
175
  begin
@@ -180,7 +180,7 @@ module RailsFailover
180
180
 
181
181
  waiting_since = Process.clock_gettime(Process::CLOCK_MONOTONIC)
182
182
  loop do # Keep trying
183
- break if has_lock = redis.mon_try_enter
183
+ break if has_lock = redis_mon_try_enter(redis)
184
184
  break if !client.connection.connected? # Disconnected by other thread
185
185
  break if client.connection.rails_failover_role != role # Reconnected by other thread
186
186
  time_now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@@ -191,12 +191,28 @@ module RailsFailover
191
191
 
192
192
  client.disconnect if client.connection&.rails_failover_role == role
193
193
  ensure
194
- redis.mon_exit if has_lock
194
+ redis_mon_exit(redis) if has_lock
195
195
  end
196
196
 
197
197
  def logger
198
198
  RailsFailover::Redis.logger
199
199
  end
200
+
201
+ def redis_mon_try_enter(redis)
202
+ if redis.respond_to? :mon_try_enter
203
+ redis.mon_try_enter
204
+ else
205
+ redis.instance_variable_get(:@monitor).mon_try_enter
206
+ end
207
+ end
208
+
209
+ def redis_mon_exit(redis)
210
+ if redis.respond_to? :mon_exit
211
+ redis.mon_exit
212
+ else
213
+ redis.instance_variable_get(:@monitor).mon_exit
214
+ end
215
+ end
200
216
  end
201
217
  end
202
218
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsFailover
4
- VERSION = "0.6.5"
4
+ VERSION = "0.8.1"
5
5
  end
@@ -9,8 +9,9 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["tgx@discourse.org"]
10
10
 
11
11
  spec.summary = %q{Failover for ActiveRecord and Redis}
12
+ spec.homepage = "https://github.com/discourse/rails_failover"
12
13
  spec.license = "MIT"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
14
15
 
15
16
  # Specify which files should be added to the gem when it is released.
16
17
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -21,8 +22,8 @@ Gem::Specification.new do |spec|
21
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
23
  spec.require_paths = ["lib"]
23
24
 
24
- ["activerecord", "railties"].each do |gem_name|
25
- spec.add_dependency gem_name, "~> 6.0"
26
- end
25
+ spec.add_dependency "activerecord", "> 6.0", "< 7.1"
26
+ spec.add_dependency "railties", "> 6.0", "< 7.1"
27
+
27
28
  spec.add_dependency "concurrent-ruby"
28
29
  end
metadata CHANGED
@@ -1,43 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_failover
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Tan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-16 00:00:00.000000000 Z
11
+ date: 2022-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '6.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7.1'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '6.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7.1'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: railties
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - "~>"
37
+ - - ">"
32
38
  - !ruby/object:Gem::Version
33
39
  version: '6.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '7.1'
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - "~>"
47
+ - - ">"
39
48
  - !ruby/object:Gem::Version
40
49
  version: '6.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '7.1'
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: concurrent-ruby
43
55
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +64,7 @@ dependencies:
52
64
  - - ">="
53
65
  - !ruby/object:Gem::Version
54
66
  version: '0'
55
- description:
67
+ description:
56
68
  email:
57
69
  - tgx@discourse.org
58
70
  executables: []
@@ -66,7 +78,6 @@ files:
66
78
  - CHANGELOG.md
67
79
  - CODE_OF_CONDUCT.md
68
80
  - Gemfile
69
- - Gemfile.lock
70
81
  - LICENSE.txt
71
82
  - README.md
72
83
  - Rakefile
@@ -87,11 +98,11 @@ files:
87
98
  - postgresql.mk
88
99
  - rails_failover.gemspec
89
100
  - redis.mk
90
- homepage:
101
+ homepage: https://github.com/discourse/rails_failover
91
102
  licenses:
92
103
  - MIT
93
104
  metadata: {}
94
- post_install_message:
105
+ post_install_message:
95
106
  rdoc_options: []
96
107
  require_paths:
97
108
  - lib
@@ -99,15 +110,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
110
  requirements:
100
111
  - - ">="
101
112
  - !ruby/object:Gem::Version
102
- version: 2.3.0
113
+ version: 2.5.0
103
114
  required_rubygems_version: !ruby/object:Gem::Requirement
104
115
  requirements:
105
116
  - - ">="
106
117
  - !ruby/object:Gem::Version
107
118
  version: '0'
108
119
  requirements: []
109
- rubygems_version: 3.1.4
110
- signing_key:
120
+ rubygems_version: 3.1.6
121
+ signing_key:
111
122
  specification_version: 4
112
123
  summary: Failover for ActiveRecord and Redis
113
124
  test_files: []
data/Gemfile.lock DELETED
@@ -1,123 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- rails_failover (0.6.5)
5
- activerecord (~> 6.0)
6
- concurrent-ruby
7
- railties (~> 6.0)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- actionpack (6.0.3.1)
13
- actionview (= 6.0.3.1)
14
- activesupport (= 6.0.3.1)
15
- rack (~> 2.0, >= 2.0.8)
16
- rack-test (>= 0.6.3)
17
- rails-dom-testing (~> 2.0)
18
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
19
- actionview (6.0.3.1)
20
- activesupport (= 6.0.3.1)
21
- builder (~> 3.1)
22
- erubi (~> 1.4)
23
- rails-dom-testing (~> 2.0)
24
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
25
- activemodel (6.0.3.1)
26
- activesupport (= 6.0.3.1)
27
- activerecord (6.0.3.1)
28
- activemodel (= 6.0.3.1)
29
- activesupport (= 6.0.3.1)
30
- activesupport (6.0.3.1)
31
- concurrent-ruby (~> 1.0, >= 1.0.2)
32
- i18n (>= 0.7, < 2)
33
- minitest (~> 5.1)
34
- tzinfo (~> 1.1)
35
- zeitwerk (~> 2.2, >= 2.2.2)
36
- ast (2.4.0)
37
- builder (3.2.4)
38
- byebug (11.1.3)
39
- concurrent-ruby (1.1.6)
40
- crass (1.0.6)
41
- diff-lcs (1.3)
42
- erubi (1.10.0)
43
- i18n (1.8.2)
44
- concurrent-ruby (~> 1.0)
45
- loofah (2.7.0)
46
- crass (~> 1.0.2)
47
- nokogiri (>= 1.5.9)
48
- method_source (1.0.0)
49
- mini_portile2 (2.4.0)
50
- minitest (5.14.1)
51
- nokogiri (1.10.10)
52
- mini_portile2 (~> 2.4.0)
53
- parallel (1.19.1)
54
- parser (2.7.1.2)
55
- ast (~> 2.4.0)
56
- pg (1.2.3)
57
- rack (2.2.3)
58
- rack-test (1.1.0)
59
- rack (>= 1.0, < 3)
60
- rails-dom-testing (2.0.3)
61
- activesupport (>= 4.2.0)
62
- nokogiri (>= 1.6)
63
- rails-html-sanitizer (1.3.0)
64
- loofah (~> 2.3)
65
- railties (6.0.3.1)
66
- actionpack (= 6.0.3.1)
67
- activesupport (= 6.0.3.1)
68
- method_source
69
- rake (>= 0.8.7)
70
- thor (>= 0.20.3, < 2.0)
71
- rainbow (3.0.0)
72
- rake (12.3.3)
73
- redis (4.1.4)
74
- rexml (3.2.4)
75
- rspec (3.9.0)
76
- rspec-core (~> 3.9.0)
77
- rspec-expectations (~> 3.9.0)
78
- rspec-mocks (~> 3.9.0)
79
- rspec-core (3.9.2)
80
- rspec-support (~> 3.9.3)
81
- rspec-expectations (3.9.2)
82
- diff-lcs (>= 1.2.0, < 2.0)
83
- rspec-support (~> 3.9.0)
84
- rspec-mocks (3.9.1)
85
- diff-lcs (>= 1.2.0, < 2.0)
86
- rspec-support (~> 3.9.0)
87
- rspec-support (3.9.3)
88
- rubocop (0.83.0)
89
- parallel (~> 1.10)
90
- parser (>= 2.7.0.1)
91
- rainbow (>= 2.2.2, < 4.0)
92
- rexml
93
- ruby-progressbar (~> 1.7)
94
- unicode-display_width (>= 1.4.0, < 2.0)
95
- rubocop-discourse (2.1.2)
96
- rubocop (>= 0.69.0)
97
- rubocop-rspec (>= 1.39.0)
98
- rubocop-rspec (1.39.0)
99
- rubocop (>= 0.68.1)
100
- ruby-progressbar (1.10.1)
101
- thor (1.0.1)
102
- thread_safe (0.3.6)
103
- tzinfo (1.2.7)
104
- thread_safe (~> 0.1)
105
- unicode-display_width (1.7.0)
106
- zeitwerk (2.3.0)
107
-
108
- PLATFORMS
109
- ruby
110
-
111
- DEPENDENCIES
112
- activerecord (~> 6.0)
113
- byebug
114
- pg (~> 1.2)
115
- rack
116
- rails_failover!
117
- rake (~> 12.0)
118
- redis (~> 4.1)
119
- rspec (~> 3.0)
120
- rubocop-discourse
121
-
122
- BUNDLED WITH
123
- 2.1.4