rails-pg-adapter 0.1.11 → 0.1.13

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: 97170715fde6ba059d296a9fbce17b22b1c0e4a40d48473992d02d8368b96963
4
- data.tar.gz: 51099b75bbaaa27a0f8120a865da60da33a21e35b262802843ba29791c8d572f
3
+ metadata.gz: ee063dc61ffb7297dd7591706c9cfb816dbbe1a407abf9d997a6c151cab1ad49
4
+ data.tar.gz: f80b24aed7b4c65d73af05cac66d35dd25a0fb7d80f7f5fff9423a833d857745
5
5
  SHA512:
6
- metadata.gz: 1458a06466189759dee8b82cea49adbf856cac36937ead93975d47439d4f962033a5a4c01f9bcce871c919a0c7c4341f7b07c62c7c5f882cd98ffde70b685e06
7
- data.tar.gz: 563aef7c452bfd98266543597ed5cb2502d2047fe0cd586522bc431aa441b86b799c494a5f4c69f03047a52fba2a5b916dac553160f07976e6b05445e431454c
6
+ metadata.gz: 206eedbdd47a2a56a41a4386cb213aded7beeec53e375ec6adb13b116defac8cdfe506e1f989dc511189e8474d072a2776f94dabb2b751ba9576f1dff2e144f7
7
+ data.tar.gz: 716f19553e8f15afae93d099f4e5ec81927d9f7a69f134fc92e97e83aa428bc30ccf7947fa59727db6a0c142de576823ecdda4c022352f8e726bf1bc97f99458
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.1.13] - 2023-05-09
2
+
3
+ - Use throw_away! instead and capture state of transaction and re-raise accordingly
4
+
5
+ ## [0.1.12] - 2023-05-08
6
+
7
+ - Slight refactor and reduce multiple disconnect attempts
8
+
1
9
  ## [0.1.11] - 2023-05-08
2
10
 
3
11
  - Attempt a re-connect before a retry
@@ -44,40 +44,56 @@ module RailsPgAdapter
44
44
  def exec_cache(*args)
45
45
  sleep_times = ::RailsPgAdapter.configuration.reconnect_with_backoff.dup
46
46
  query, _ = args
47
+ within_transaction = in_transaction? # capture in_transaction? state before retries
47
48
  begin
48
49
  super(*args)
49
50
  rescue ::ActiveRecord::StatementInvalid,
50
51
  ::ActiveRecord::ConnectionNotEstablished,
51
52
  ::ActiveRecord::NoDatabaseError => e
52
53
  raise unless ::RailsPgAdapter::Patch.supported_errors?(e)
54
+ handle_schema_cache_error(e)
55
+ handle_activerecord_error(e)
56
+ raise if within_transaction
57
+ raise unless try_reconnect?(e)
53
58
 
54
- handle_error(e) unless try_reconnect?(e)
55
59
  sleep_time = sleep_times.shift
56
- handle_error(e) unless sleep_time
57
- warn("Retry query failed, retrying again in #{sleep_time} sec. Retrying: #{query}")
58
- sleep(sleep_time)
59
- connect
60
- retry
60
+ if sleep_time
61
+ warn("Retry query failed, retrying again in #{sleep_time} sec. Retrying: #{query}")
62
+ sleep(sleep_time)
63
+ connect
64
+ retry
65
+ else
66
+ handle_activerecord_error(e)
67
+ raise
68
+ end
61
69
  end
62
70
  end
63
71
 
64
72
  def exec_no_cache(*args)
65
73
  sleep_times = ::RailsPgAdapter.configuration.reconnect_with_backoff.dup
66
74
  query, _ = args
75
+ within_transaction = in_transaction? # capture in_transaction? state before retries
67
76
  begin
68
77
  super(*args)
69
78
  rescue ::ActiveRecord::StatementInvalid,
70
79
  ::ActiveRecord::ConnectionNotEstablished,
71
80
  ::ActiveRecord::NoDatabaseError => e
72
81
  raise unless ::RailsPgAdapter::Patch.supported_errors?(e)
82
+ handle_schema_cache_error(e)
83
+ handle_activerecord_error(e)
84
+ raise if within_transaction
85
+ raise unless try_reconnect?(e)
73
86
 
74
- handle_error(e) unless try_reconnect?(e)
75
87
  sleep_time = sleep_times.shift
76
- handle_error(e) unless sleep_time
77
- warn("Retry query failed, retrying again in #{sleep_time} sec. Retrying: #{query}")
78
- sleep(sleep_time)
79
- connect
80
- retry
88
+ if sleep_time
89
+ warn("Retry query failed, retrying again in #{sleep_time} sec. Retrying: #{query}")
90
+ sleep(sleep_time)
91
+ connect
92
+ retry
93
+ else
94
+ handle_activerecord_error(e)
95
+ raise
96
+ end
81
97
  end
82
98
  end
83
99
 
@@ -85,33 +101,23 @@ module RailsPgAdapter
85
101
  return false if in_transaction?
86
102
  return false unless ::RailsPgAdapter::Patch.failover_error?(e.message)
87
103
  return false unless ::RailsPgAdapter.reconnect_with_backoff?
88
-
89
- begin
90
- disconnect_conn!
91
- true
92
- rescue ::ActiveRecord::ConnectionNotEstablished
93
- false
94
- end
104
+ true
95
105
  end
96
106
 
97
- def handle_error(e)
98
- if ::RailsPgAdapter::Patch.failover_error?(e.message)
99
- warn("clearing connections due to #{e} - #{e.message}")
100
- disconnect_conn!
101
- end
107
+ def handle_activerecord_error(e)
108
+ return unless ::RailsPgAdapter::Patch.failover_error?(e.message)
109
+ warn("clearing connections due to #{e} - #{e.message}")
110
+ throw_away!
111
+ end
102
112
 
103
- raise(e) unless ::RailsPgAdapter::Patch.missing_column_error?(e.message)
113
+ def handle_schema_cache_error(e)
114
+ return unless ::RailsPgAdapter::Patch.missing_column_error?(e.message)
104
115
  warn("clearing column information due to #{e} - #{e.message}")
105
116
 
106
117
  internal_clear_schema_cache!
107
118
  raise(e)
108
119
  end
109
120
 
110
- def disconnect_conn!
111
- disconnect!
112
- ::ActiveRecord::Base.connection_pool.remove(::ActiveRecord::Base.connection)
113
- end
114
-
115
121
  def internal_clear_schema_cache!
116
122
  ::ActiveRecord::Base.connection_pool.connections.each { |conn| conn.schema_cache.clear! }
117
123
  ::ActiveRecord::Base.descendants.each(&:reset_column_information)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsPgAdapter
4
- VERSION = "0.1.11"
4
+ VERSION = "0.1.13"
5
5
  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.11
4
+ version: 0.1.13
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-05-08 00:00:00.000000000 Z
11
+ date: 2023-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails