rails-pg-adapter 0.1.7 → 0.1.8
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 +4 -4
- data/lib/rails_pg_adapter/patch.rb +34 -30
- data/lib/rails_pg_adapter/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: 17e38c0c8aeb60de1697257595dd0123a262d7e6a10a996de13086e826da96a7
|
4
|
+
data.tar.gz: 2bb519b103a9027848ae3ca963efc66f57d47b2b34be969657035c7a4f35256b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f65dba534475afa8db2028ec685822c86d2c80df01ef29b99212440d032b797c3a99cad2150d4276802df26fed34e45fd0810f9051f4e4ce57e4d657898aebd2
|
7
|
+
data.tar.gz: 80c9d7257edfefc0f452930cc84f864056df43b1cfea3c2705397411e297c6dce02fa4d43ae55bc0a188a49d778514caa9df6341e36154408a243376880040d1
|
@@ -20,16 +20,33 @@ module RailsPgAdapter
|
|
20
20
|
CONNECTION_SCHEMA_ERROR = ["PG::UndefinedColumn"].freeze
|
21
21
|
CONNECTION_SCHEMA_RE = /#{CONNECTION_SCHEMA_ERROR.map { |w| Regexp.escape(w) }.join("|")}/.freeze
|
22
22
|
|
23
|
+
class << self
|
24
|
+
def supported_errors?(e)
|
25
|
+
return true if failover_error?(e.message)
|
26
|
+
return true if missing_column_error?(e.message)
|
27
|
+
false
|
28
|
+
end
|
29
|
+
|
30
|
+
def failover_error?(error_message)
|
31
|
+
CONNECTION_ERROR_RE.match?(error_message) && ::RailsPgAdapter.failover_patch?
|
32
|
+
end
|
33
|
+
|
34
|
+
def missing_column_error?(error_message)
|
35
|
+
CONNECTION_SCHEMA_RE.match?(error_message) &&
|
36
|
+
::RailsPgAdapter.reset_column_information_patch?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
23
40
|
private
|
24
41
|
|
25
42
|
def exec_cache(*args)
|
26
|
-
sleep_times = RailsPgAdapter.configuration.reconnect_with_backoff.dup
|
43
|
+
sleep_times = ::RailsPgAdapter.configuration.reconnect_with_backoff.dup
|
27
44
|
begin
|
28
45
|
super(*args)
|
29
46
|
rescue ::ActiveRecord::StatementInvalid,
|
30
47
|
::ActiveRecord::ConnectionNotEstablished,
|
31
48
|
::ActiveRecord::NoDatabaseError => e
|
32
|
-
raise unless supported_errors?(e)
|
49
|
+
raise unless ::RailsPgAdapter::Patch.supported_errors?(e)
|
33
50
|
|
34
51
|
if try_reconnect?(e)
|
35
52
|
sleep_time = sleep_times.shift
|
@@ -44,13 +61,13 @@ module RailsPgAdapter
|
|
44
61
|
end
|
45
62
|
|
46
63
|
def exec_no_cache(*args)
|
47
|
-
sleep_times = RailsPgAdapter.configuration.reconnect_with_backoff.dup
|
64
|
+
sleep_times = ::RailsPgAdapter.configuration.reconnect_with_backoff.dup
|
48
65
|
begin
|
49
66
|
super(*args)
|
50
67
|
rescue ::ActiveRecord::StatementInvalid,
|
51
68
|
::ActiveRecord::ConnectionNotEstablished,
|
52
69
|
::ActiveRecord::NoDatabaseError => e
|
53
|
-
raise unless supported_errors?(e)
|
70
|
+
raise unless ::RailsPgAdapter::Patch.supported_errors?(e)
|
54
71
|
|
55
72
|
if try_reconnect?(e)
|
56
73
|
sleep_time = sleep_times.shift
|
@@ -66,8 +83,8 @@ module RailsPgAdapter
|
|
66
83
|
|
67
84
|
def try_reconnect?(e)
|
68
85
|
return false if in_transaction?
|
69
|
-
return false unless failover_error?(e.message)
|
70
|
-
return false unless RailsPgAdapter.reconnect_with_backoff?
|
86
|
+
return false unless ::RailsPgAdapter::Patch.failover_error?(e.message)
|
87
|
+
return false unless ::RailsPgAdapter.reconnect_with_backoff?
|
71
88
|
|
72
89
|
begin
|
73
90
|
disconnect_conn!
|
@@ -78,15 +95,13 @@ module RailsPgAdapter
|
|
78
95
|
end
|
79
96
|
|
80
97
|
def handle_error(e)
|
81
|
-
if failover_error?(e.message)
|
98
|
+
if ::RailsPgAdapter::Patch.failover_error?(e.message)
|
82
99
|
warn("clearing connections due to #{e} - #{e.message}")
|
83
100
|
disconnect_conn!
|
84
101
|
raise(e)
|
85
102
|
end
|
86
103
|
|
87
|
-
unless missing_column_error?(e.message)
|
88
|
-
return
|
89
|
-
end
|
104
|
+
return unless ::RailsPgAdapter::Patch.missing_column_error?(e.message)
|
90
105
|
|
91
106
|
warn("clearing column information due to #{e} - #{e.message}")
|
92
107
|
|
@@ -94,14 +109,6 @@ module RailsPgAdapter
|
|
94
109
|
raise
|
95
110
|
end
|
96
111
|
|
97
|
-
def failover_error?(error_message)
|
98
|
-
CONNECTION_ERROR_RE.match?(error_message)
|
99
|
-
end
|
100
|
-
|
101
|
-
def missing_column_error?(error_message)
|
102
|
-
CONNECTION_SCHEMA_RE.match?(error_message)
|
103
|
-
end
|
104
|
-
|
105
112
|
def disconnect_conn!
|
106
113
|
disconnect!
|
107
114
|
::ActiveRecord::Base.connection_pool.remove(::ActiveRecord::Base.connection)
|
@@ -115,15 +122,7 @@ module RailsPgAdapter
|
|
115
122
|
def warn(msg)
|
116
123
|
return unless defined?(Rails)
|
117
124
|
return if Rails.logger.nil?
|
118
|
-
::Rails.logger.warn("[RailsPgAdapter::Patch] #{msg}")
|
119
|
-
end
|
120
|
-
|
121
|
-
def supported_errors?(e)
|
122
|
-
return true if failover_error?(e.message) && RailsPgAdapter.failover_patch?
|
123
|
-
if missing_column_error?(e.message) && RailsPgAdapter.reset_column_information_patch?
|
124
|
-
return true
|
125
|
-
end
|
126
|
-
false
|
125
|
+
::Rails.logger.warn("[::RailsPgAdapter::Patch] #{msg}")
|
127
126
|
end
|
128
127
|
end
|
129
128
|
end
|
@@ -138,15 +137,20 @@ module ActiveRecord
|
|
138
137
|
old_new_client_method = instance_method(:new_client)
|
139
138
|
|
140
139
|
define_method(:new_client) do |args|
|
141
|
-
sleep_times = RailsPgAdapter.configuration.reconnect_with_backoff.dup
|
140
|
+
sleep_times = ::RailsPgAdapter.configuration.reconnect_with_backoff.dup
|
142
141
|
begin
|
143
142
|
old_new_client_method.bind(self).call(args)
|
144
143
|
rescue ::ActiveRecord::ConnectionNotEstablished, ::ActiveRecord::NoDatabaseError => e
|
145
|
-
|
144
|
+
unless ::RailsPgAdapter::Patch.supported_errors?(e) &&
|
145
|
+
::RailsPgAdapter.reconnect_with_backoff?
|
146
|
+
raise
|
147
|
+
end
|
146
148
|
|
147
149
|
sleep_time = sleep_times.shift
|
148
150
|
raise unless sleep_time
|
149
|
-
warn(
|
151
|
+
warn(
|
152
|
+
"Could not establish a connection from new_client, retrying again in #{sleep_time} sec.",
|
153
|
+
)
|
150
154
|
sleep(sleep_time)
|
151
155
|
retry
|
152
156
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-pg-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tines Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|