rails_failover 0.5.0 → 0.5.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: 6ab1bfea9c1e882693a3455a73601edce7c0ed2af5b50ec1276cf95e1dda51d5
4
- data.tar.gz: 4cf4386f6d51dbae3f82bedcb56c8da3ac4674b254a1b475e2822b46d4a5b8ed
3
+ metadata.gz: de312681fb912d8d00ffaaf362f8c2201a95066660759aa92393d3212753e6c9
4
+ data.tar.gz: 006af26908149488773d664dea57d761ff24304516ae7b65139b20d288f0ab85
5
5
  SHA512:
6
- metadata.gz: 4b22d9f037c18ca0c82a61764494e5b8a3a41a30a514b12f8d9dec1737e24fb251729457abb8e0f3ab596ab511db98e776740b7a62646313dd542c10c945cbce
7
- data.tar.gz: a653959c37717e01e30ff82c0b1594b71e2a402c13073c6e0bf1ee6176d588dc2fcd3c165cd69e294c7fbe0b66bc0e944e36e5fb176b7306ac92dc028a15fb0b
6
+ metadata.gz: 634c701d2d4ba73e4b45efed2de949797521c7d390586eeec412f3d6749d93b446bde1b51b53ddc37a41d0e3e79d18902a154a22e07f1bad8528d365822f0614
7
+ data.tar.gz: 7c4126b04c1792cb26c98f3532e3cc815d0aaca6aed9cda20831315f826075b362d23d5863c942415a018157553e156e24c9dff128751ea5138c59f6799efecd
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_failover (0.5.0)
4
+ rails_failover (0.5.1)
5
5
  activerecord (~> 6.0)
6
6
  railties (~> 6.0)
7
7
 
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require 'singleton'
3
3
  require 'monitor'
4
- require 'fileutils'
5
4
 
6
5
  module RailsFailover
7
6
  module ActiveRecord
@@ -9,7 +8,6 @@ module RailsFailover
9
8
  include Singleton
10
9
  include MonitorMixin
11
10
 
12
- SEPERATOR = "__RAILS_FAILOVER__"
13
11
  VERIFY_FREQUENCY_BUFFER_PRECENT = 20
14
12
 
15
13
  def initialize
@@ -3,40 +3,49 @@
3
3
  module RailsFailover
4
4
  module ActiveRecord
5
5
  class Railtie < ::Rails::Railtie
6
- initializer "rails_failover.init", after: "active_record.initialize_database" do
7
- ::ActiveSupport.on_load(:active_record) do
8
- Handler.instance
9
-
10
- # We are doing this manually for now since we're awaiting Rails 6.1 to be released which will
11
- # have more stable ActiveRecord APIs for handling multiple databases with different roles.
12
- ::ActiveRecord::Base.connection_handlers[::ActiveRecord::Base.reading_role] =
13
- ::ActiveRecord::ConnectionAdapters::ConnectionHandler.new
14
-
15
- ::ActiveRecord::Base.connection_handlers[::ActiveRecord::Base.writing_role].connection_pools.each do |connection_pool|
16
- RailsFailover::ActiveRecord.establish_reading_connection(
17
- ::ActiveRecord::Base.connection_handlers[::ActiveRecord::Base.reading_role],
18
- connection_pool.spec
19
- )
20
- end
6
+ initializer "rails_failover.init", after: "active_record.initialize_database" do |app|
7
+ config = ::ActiveRecord::Base.connection_config
8
+ app.config.active_record_rails_failover = false
9
+
10
+ if !!(config[:replica_host] && config[:replica_port])
11
+ app.config.active_record_rails_failover = true
12
+
13
+ ::ActiveSupport.on_load(:active_record) do
14
+ Handler.instance
15
+
16
+ # We are doing this manually for now since we're awaiting Rails 6.1 to be released which will
17
+ # have more stable ActiveRecord APIs for handling multiple databases with different roles.
18
+ ::ActiveRecord::Base.connection_handlers[::ActiveRecord::Base.reading_role] =
19
+ ::ActiveRecord::ConnectionAdapters::ConnectionHandler.new
21
20
 
22
- begin
23
- ::ActiveRecord::Base.connection
24
- rescue ::ActiveRecord::NoDatabaseError
25
- # Do nothing since database hasn't been created
26
- rescue ::PG::Error => e
27
- Handler.instance.verify_primary(::ActiveRecord::Base.writing_role)
28
- ::ActiveRecord::Base.connection_handler = ::ActiveRecord::Base.lookup_connection_handler(:reading)
21
+ ::ActiveRecord::Base.connection_handlers[::ActiveRecord::Base.writing_role].connection_pools.each do |connection_pool|
22
+ RailsFailover::ActiveRecord.establish_reading_connection(
23
+ ::ActiveRecord::Base.connection_handlers[::ActiveRecord::Base.reading_role],
24
+ connection_pool.spec
25
+ )
26
+ end
27
+
28
+ begin
29
+ ::ActiveRecord::Base.connection
30
+ rescue ::ActiveRecord::NoDatabaseError
31
+ # Do nothing since database hasn't been created
32
+ rescue ::PG::Error => e
33
+ Handler.instance.verify_primary(::ActiveRecord::Base.writing_role)
34
+ ::ActiveRecord::Base.connection_handler = ::ActiveRecord::Base.lookup_connection_handler(:reading)
35
+ end
29
36
  end
30
37
  end
31
38
  end
32
39
 
33
40
  initializer "rails_failover.insert_middleware" do |app|
34
- ActionDispatch::DebugExceptions.register_interceptor do |request, exception|
35
- RailsFailover::ActiveRecord::Interceptor.handle(request, exception)
36
- end
41
+ if app.config.active_record_rails_failover
42
+ ActionDispatch::DebugExceptions.register_interceptor do |request, exception|
43
+ RailsFailover::ActiveRecord::Interceptor.handle(request, exception)
44
+ end
37
45
 
38
- if !skip_middleware?(app.config)
39
- app.middleware.unshift(::RailsFailover::ActiveRecord::Middleware)
46
+ if !skip_middleware?(app.config)
47
+ app.middleware.unshift(::RailsFailover::ActiveRecord::Middleware)
48
+ end
40
49
  end
41
50
  end
42
51
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'monitor'
4
4
  require 'singleton'
5
- require 'digest'
6
5
 
7
6
  module RailsFailover
8
7
  class Redis
@@ -13,7 +12,6 @@ module RailsFailover
13
12
  PRIMARY_ROLE_STATUS = "role:master"
14
13
  PRIMARY_LOADED_STATUS = "loading:0"
15
14
  VERIFY_FREQUENCY_BUFFER_PRECENT = 20
16
- SEPERATOR = "__RAILS_FAILOVER__"
17
15
 
18
16
  def initialize
19
17
  @primaries_down = {}
@@ -123,10 +121,6 @@ module RailsFailover
123
121
 
124
122
  private
125
123
 
126
- def id_digest(id)
127
- Digest::MD5.hexdigest(id)
128
- end
129
-
130
124
  def all_primaries_up
131
125
  mon_synchronize { primaries_down.empty? }
132
126
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsFailover
4
- VERSION = "0.5.0"
4
+ VERSION = "0.5.1"
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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alan Tan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-15 00:00:00.000000000 Z
11
+ date: 2020-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord