rails_failover 0.5.0 → 0.5.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de312681fb912d8d00ffaaf362f8c2201a95066660759aa92393d3212753e6c9
|
4
|
+
data.tar.gz: 006af26908149488773d664dea57d761ff24304516ae7b65139b20d288f0ab85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 634c701d2d4ba73e4b45efed2de949797521c7d390586eeec412f3d6749d93b446bde1b51b53ddc37a41d0e3e79d18902a154a22e07f1bad8528d365822f0614
|
7
|
+
data.tar.gz: 7c4126b04c1792cb26c98f3532e3cc815d0aaca6aed9cda20831315f826075b362d23d5863c942415a018157553e156e24c9dff128751ea5138c59f6799efecd
|
data/Gemfile.lock
CHANGED
@@ -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
|
-
::
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
39
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2020-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|