activerecord-mysql-reconnect-new 0.6.0
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 +7 -0
- data/.gitignore +21 -0
- data/.idea/.gitignore +8 -0
- data/.idea/activerecord-mysql-reconnect.iml +22 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/.rspec +3 -0
- data/.travis.yml +45 -0
- data/Appraisals +28 -0
- data/ChangeLog +35 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +124 -0
- data/Rakefile +5 -0
- data/activerecord-mysql-reconnect-new.gemspec +28 -0
- data/docker-compose.yml +6 -0
- data/gemfiles/activerecord_4.2.gemfile +8 -0
- data/gemfiles/activerecord_5.0.gemfile +7 -0
- data/gemfiles/activerecord_5.1.gemfile +7 -0
- data/gemfiles/activerecord_5.2.gemfile +7 -0
- data/gemfiles/activerecord_6.0.gemfile +7 -0
- data/gemfiles/activerecord_6.1.gemfile +7 -0
- data/gemfiles/activerecord_master.gemfile +7 -0
- data/lib/activerecord/mysql/reconnect/abstract_mysql_adapter_ext.rb +46 -0
- data/lib/activerecord/mysql/reconnect/base_ext.rb +32 -0
- data/lib/activerecord/mysql/reconnect/connection_pool_ext.rb +18 -0
- data/lib/activerecord/mysql/reconnect/mysql2_adapter_ext.rb +13 -0
- data/lib/activerecord/mysql/reconnect/null_transaction_ext.rb +9 -0
- data/lib/activerecord/mysql/reconnect/version.rb +7 -0
- data/lib/activerecord/mysql/reconnect.rb +268 -0
- data/lib/activerecord-mysql-reconnect.rb +5 -0
- data/spec/activerecord-mysql-reconnect_spec.rb +545 -0
- data/spec/data.sql +1001 -0
- data/spec/employee_model.rb +1 -0
- data/spec/mysql2_ext.rb +5 -0
- data/spec/mysql_helper.rb +84 -0
- data/spec/spec_helper.rb +54 -0
- metadata +174 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 40cb9b6f448d37763a9d1e12f54ab8ea980a31127a813865f11b8addf9a8cb7c
|
4
|
+
data.tar.gz: 55db8677ac2c73a1fb702ea25670a596dc5f614de5142fd6f83c02d458fde8df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b9bdff5e005aed4038a7460feb0b1546d1473d3346d3471231442a6bed1d690fe3261602e34b4f10400a6315830b6b07e2eb316a9be31f22276fa9f40555229d
|
7
|
+
data.tar.gz: ea1fd650384e2589123b212060b98187d8f0d964c95cabbe2a80e820b408310a1c6c7e1b4454360d052d48ac9aae195d06d858f6e5907c800d90b28c8b10db02
|
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
test.rb
|
19
|
+
*.bak
|
20
|
+
*.swp
|
21
|
+
/gemfiles/*.lock
|
data/.idea/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
6
|
+
<component name="NewModuleRootManager">
|
7
|
+
<content url="file://$MODULE_DIR$">
|
8
|
+
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
9
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
|
+
</content>
|
12
|
+
<orderEntry type="inheritedJdk" />
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.17.2, ruby-2.6.8-p205) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v12.3.3, ruby-2.6.8-p205) [gem]" level="application" />
|
16
|
+
</component>
|
17
|
+
<component name="RakeTasksCache">
|
18
|
+
<option name="myRootTask">
|
19
|
+
<RakeTaskImpl id="rake" />
|
20
|
+
</option>
|
21
|
+
</component>
|
22
|
+
</module>
|
data/.idea/misc.xml
ADDED
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/activerecord-mysql-reconnect.iml" filepath="$PROJECT_DIR$/.idea/activerecord-mysql-reconnect.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
data/.idea/vcs.xml
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
dist: trusty
|
2
|
+
sudo: required
|
3
|
+
language: ruby
|
4
|
+
rvm:
|
5
|
+
- 2.3.8
|
6
|
+
- 2.4.6
|
7
|
+
- 2.5.5
|
8
|
+
- 2.6.3
|
9
|
+
- 2.7.0
|
10
|
+
before_install:
|
11
|
+
- docker-compose up -d
|
12
|
+
- function mysql_ping { mysqladmin -u root -h 127.0.0.1 -ppassword ping > /dev/null 2> /dev/null; }
|
13
|
+
- for i in {1..60}; do mysql_ping && break; sleep 1; done
|
14
|
+
- gem install bundler
|
15
|
+
- docker-compose stop
|
16
|
+
script:
|
17
|
+
- bundle exec rake
|
18
|
+
gemfile:
|
19
|
+
- gemfiles/activerecord_4.2.gemfile
|
20
|
+
- gemfiles/activerecord_5.0.gemfile
|
21
|
+
- gemfiles/activerecord_5.1.gemfile
|
22
|
+
- gemfiles/activerecord_5.2.gemfile
|
23
|
+
- gemfiles/activerecord_6.0.gemfile
|
24
|
+
- gemfiles/activerecord_master.gemfile
|
25
|
+
env:
|
26
|
+
matrix:
|
27
|
+
- ACTIVERECORD_MYSQL_RECONNECT_ENGINE=InnoDB
|
28
|
+
- ACTIVERECORD_MYSQL_RECONNECT_ENGINE=MyISAM
|
29
|
+
jobs:
|
30
|
+
exclude:
|
31
|
+
- rvm: 2.3.8
|
32
|
+
gemfile: gemfiles/activerecord_6.0.gemfile
|
33
|
+
- rvm: 2.3.8
|
34
|
+
gemfile: gemfiles/activerecord_master.gemfile
|
35
|
+
- rvm: 2.4.6
|
36
|
+
gemfile: gemfiles/activerecord_6.0.gemfile
|
37
|
+
- rvm: 2.4.6
|
38
|
+
gemfile: gemfiles/activerecord_master.gemfile
|
39
|
+
- rvm: 2.7.0
|
40
|
+
gemfile: gemfiles/activerecord_4.2.gemfile
|
41
|
+
addons:
|
42
|
+
apt:
|
43
|
+
packages:
|
44
|
+
- mysql-client-core-5.6
|
45
|
+
- mysql-client-5.6
|
data/Appraisals
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
appraise "activerecord-4.2" do
|
2
|
+
gem "activerecord", "~> 4.2.0"
|
3
|
+
gem "mysql2", "< 0.5"
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise "activerecord-5.0" do
|
7
|
+
gem "activerecord", "~> 5.0.0"
|
8
|
+
end
|
9
|
+
|
10
|
+
appraise "activerecord-5.1" do
|
11
|
+
gem "activerecord", "~> 5.1.0"
|
12
|
+
end
|
13
|
+
|
14
|
+
appraise "activerecord-5.2" do
|
15
|
+
gem "activerecord", "~> 5.2.0"
|
16
|
+
end
|
17
|
+
|
18
|
+
appraise "activerecord-6.0" do
|
19
|
+
gem "activerecord", "~> 6.0.2"
|
20
|
+
end
|
21
|
+
|
22
|
+
appraise "activerecord-6.1" do
|
23
|
+
gem "activerecord", "~> 6.1.5"
|
24
|
+
end
|
25
|
+
|
26
|
+
appraise "activerecord-master" do
|
27
|
+
gem "activerecord", git: "https://github.com/rails/rails.git"
|
28
|
+
end
|
data/ChangeLog
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
activerecord-mysql-reconnect-new 0.6.0 (Jul 14, 2022)
|
2
|
+
|
3
|
+
* Support Rails 6.1
|
4
|
+
|
5
|
+
activerecord-mysql-reconnect 0.4.1 (Aug 8, 2016)
|
6
|
+
|
7
|
+
* Support AR 5.0 (RP#5 @ssig33)
|
8
|
+
* Fix test (use docker-compose)
|
9
|
+
|
10
|
+
activerecord-mysql-reconnect 0.4.0 (Mar 22, 2016)
|
11
|
+
|
12
|
+
* Remove `retryable_transaction`
|
13
|
+
* Disable support AR 3.x 4.0
|
14
|
+
|
15
|
+
activerecord-mysql-reconnect 0.3.3 (Jan 18, 2014)
|
16
|
+
|
17
|
+
* use BigDecimal for sleep
|
18
|
+
* add handling error ('The MySQL server is running with the --read-only...')
|
19
|
+
|
20
|
+
activerecord-mysql-reconnect 0.3.1 (Jan 9, 2014)
|
21
|
+
|
22
|
+
* Retry mode is added
|
23
|
+
|
24
|
+
activerecord-mysql-reconnect 0.3.0 (Jan 9, 2014)
|
25
|
+
|
26
|
+
* Retry is disabled by default
|
27
|
+
* Read-only mode is added
|
28
|
+
|
29
|
+
activerecord-mysql-reconnect 0.2.0 (Jan 4, 2014)
|
30
|
+
|
31
|
+
* Retry transaction is supported
|
32
|
+
|
33
|
+
activerecord-mysql-reconnect 0.1.0 (Oct 11, 2013)
|
34
|
+
|
35
|
+
* activerecord-mysql-reconnect is released
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Genki Sugawara
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
# activerecord-mysql-reconnect
|
2
|
+
|
3
|
+
It is the library to reconnect automatically when ActiveRecord is disconnected from MySQL.
|
4
|
+
|
5
|
+
[](http://badge.fury.io/rb/activerecord-mysql-reconnect)
|
6
|
+
[](https://travis-ci.org/winebarrel/activerecord-mysql-reconnect)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'activerecord-mysql-reconnect'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install activerecord-mysql-reconnect
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'active_record'
|
26
|
+
require 'activerecord-mysql-reconnect'
|
27
|
+
require 'logger'
|
28
|
+
|
29
|
+
ActiveRecord::Base.establish_connection(
|
30
|
+
adapter: 'mysql2',
|
31
|
+
host: '127.0.0.1',
|
32
|
+
username: 'root',
|
33
|
+
database: 'employees',
|
34
|
+
)
|
35
|
+
|
36
|
+
ActiveRecord::Base.logger = Logger.new($stdout)
|
37
|
+
ActiveRecord::Base.logger.formatter = proc {|_, _, _, message| "#{message}\n" }
|
38
|
+
ActiveRecord::Base.enable_retry = true
|
39
|
+
ActiveRecord::Base.execution_tries = 3
|
40
|
+
|
41
|
+
class Employee < ActiveRecord::Base; end
|
42
|
+
|
43
|
+
p Employee.count
|
44
|
+
system('sudo /etc/init.d/mysqld restart')
|
45
|
+
p Employee.count
|
46
|
+
```
|
47
|
+
|
48
|
+
```
|
49
|
+
shell> ruby test.rb
|
50
|
+
(64.1ms) SELECT COUNT(*) FROM `employees`
|
51
|
+
300024
|
52
|
+
Stopping mysqld: [ OK ]
|
53
|
+
Starting mysqld: [ OK ]
|
54
|
+
(0.4ms) SELECT COUNT(*) FROM `employees`
|
55
|
+
Mysql2::Error: MySQL server has gone away: SELECT COUNT(*) FROM `employees`
|
56
|
+
MySQL server has gone away. Trying to reconnect in 0.5 seconds. (cause: Mysql2::Error: MySQL server has gone away: SELECT COUNT(*) FROM `employees` [ActiveRecord::StatementInvalid], connection: host=127.0.0.1;database=employees;username=root)
|
57
|
+
(101.5ms) SELECT COUNT(*) FROM `employees`
|
58
|
+
300024
|
59
|
+
```
|
60
|
+
|
61
|
+
### without_retry
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
ActiveRecord::Base.without_retry do
|
65
|
+
Employee.count
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
### Add a retry error message
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
Activerecord::Mysql::Reconnect.handle_rw_error_messages.update(
|
73
|
+
zapzapzap: 'ZapZapZap'
|
74
|
+
)
|
75
|
+
# or `Activerecord::Mysql::Reconnect.handle_r_error_messages...`
|
76
|
+
```
|
77
|
+
|
78
|
+
## Use on rails
|
79
|
+
|
80
|
+
### Gemfile
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
gem 'activerecord-mysql-reconnect'
|
84
|
+
```
|
85
|
+
|
86
|
+
### environment file
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
MyApp::Application.configure do
|
90
|
+
...
|
91
|
+
config.active_record.enable_retry = true
|
92
|
+
#config.active_record.retry_databases = :employees
|
93
|
+
# e.g. [:employees]
|
94
|
+
# ['employees', 'localhost:test', '192.168.1.1:users']
|
95
|
+
# ['192.168.%:emp\_all']
|
96
|
+
# ['emp%']
|
97
|
+
# retry_databases -> nil: retry all databases (default)
|
98
|
+
config.active_record.execution_tries = 10 # times
|
99
|
+
# execution_tries -> 0: retry indefinitely
|
100
|
+
config.active_record.execution_retry_wait = 1.5 # sec
|
101
|
+
config.active_record.retry_mode = :rw # default: `:r`, valid values: `:r`, `:rw`, `:force`
|
102
|
+
...
|
103
|
+
ene
|
104
|
+
```
|
105
|
+
|
106
|
+
## Retry mode
|
107
|
+
|
108
|
+
* `:r` Retry only SELECT / SHOW / SET
|
109
|
+
* `:rw` Retry in all SQL, but does not retry if `Lost connection` has happened in write SQL
|
110
|
+
* `:force` Retry in all SQL
|
111
|
+
|
112
|
+
## Run tests
|
113
|
+
|
114
|
+
It requires the following:
|
115
|
+
|
116
|
+
* Docker
|
117
|
+
* Docker Compose
|
118
|
+
|
119
|
+
```sh
|
120
|
+
bundle install
|
121
|
+
bundle exec appraisal install
|
122
|
+
bundle exec appraisal activerecord-4.2 rake
|
123
|
+
bundle exec appraisal activerecord-5.0 rake
|
124
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'activerecord/mysql/reconnect/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'activerecord-mysql-reconnect-new'
|
8
|
+
spec.version = Activerecord::Mysql::Reconnect::VERSION
|
9
|
+
spec.authors = ['Sundeep Yama', 'Lee Hester']
|
10
|
+
spec.email = ['sundeepyama@gmail.com', 'lhester@simplenexus.com']
|
11
|
+
spec.description = %q{It is the library to reconnect automatically when ActiveRecord is disconnected from MySQL.}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = 'https://github.com/SimpleNexus/activerecord-mysql-reconnect'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
# '~> 4.2.6'
|
22
|
+
spec.add_dependency 'activerecord'
|
23
|
+
spec.add_dependency 'mysql2'
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rspec', '>= 3.0.0'
|
27
|
+
spec.add_development_dependency "appraisal"
|
28
|
+
end
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Activerecord::Mysql::Reconnect::ExecuteWithReconnect
|
2
|
+
def execute(sql, name = nil)
|
3
|
+
retryable(sql, name) do |sql_names|
|
4
|
+
retval = nil
|
5
|
+
|
6
|
+
sql_names.each do |s, n|
|
7
|
+
retval = super(s, n)
|
8
|
+
end
|
9
|
+
|
10
|
+
retval
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
|
16
|
+
prepend Activerecord::Mysql::Reconnect::ExecuteWithReconnect
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def retryable(sql, name, &block)
|
21
|
+
block_with_reconnect = nil
|
22
|
+
sql_names = [[sql, name]]
|
23
|
+
transaction = current_transaction
|
24
|
+
|
25
|
+
if sql =~ /\ABEGIN\z/i and transaction.is_a?(ActiveRecord::ConnectionAdapters::NullTransaction)
|
26
|
+
def transaction.state; nil; end
|
27
|
+
end
|
28
|
+
|
29
|
+
Activerecord::Mysql::Reconnect.retryable(
|
30
|
+
:proc => proc {
|
31
|
+
(block_with_reconnect || block).call(sql_names)
|
32
|
+
},
|
33
|
+
:on_error => proc {
|
34
|
+
unless block_with_reconnect
|
35
|
+
block_with_reconnect = proc do |i|
|
36
|
+
reconnect_without_retry!
|
37
|
+
block.call(i)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
},
|
41
|
+
:sql => sql,
|
42
|
+
:retry_mode => Activerecord::Mysql::Reconnect.retry_mode,
|
43
|
+
:connection => @connection
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class ActiveRecord::Base
|
2
|
+
class_attribute :execution_tries, :instance_accessor => false
|
3
|
+
class_attribute :execution_retry_wait, :instance_accessor => false
|
4
|
+
class_attribute :enable_retry, :instance_accessor => false
|
5
|
+
|
6
|
+
RETRY_MODES = [:r, :rw, :force]
|
7
|
+
DEFAULT_RETRY_MODE = :r
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def retry_mode=(v)
|
11
|
+
Activerecord::Mysql::Reconnect.retry_mode = v
|
12
|
+
end
|
13
|
+
|
14
|
+
def retry_mode
|
15
|
+
Activerecord::Mysql::Reconnect.retry_mode
|
16
|
+
end
|
17
|
+
|
18
|
+
def retry_databases=(v)
|
19
|
+
Activerecord::Mysql::Reconnect.retry_databases = v
|
20
|
+
end
|
21
|
+
|
22
|
+
def retry_databases
|
23
|
+
Activerecord::Mysql::Reconnect.retry_databases
|
24
|
+
end
|
25
|
+
|
26
|
+
def without_retry
|
27
|
+
Activerecord::Mysql::Reconnect.without_retry do
|
28
|
+
yield
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Activerecord::Mysql::Reconnect::NewConnectionWithRetry
|
2
|
+
def new_connection
|
3
|
+
if defined?(db_config)
|
4
|
+
Activerecord::Mysql::Reconnect.retryable(
|
5
|
+
:proc => proc { super },
|
6
|
+
:connection => db_config.configuration_hash
|
7
|
+
)
|
8
|
+
else
|
9
|
+
Activerecord::Mysql::Reconnect.retryable(
|
10
|
+
:proc => proc { super },
|
11
|
+
:connection => spec.config,
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
class ActiveRecord::ConnectionAdapters::ConnectionPool
|
17
|
+
prepend Activerecord::Mysql::Reconnect::NewConnectionWithRetry
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Activerecord::Mysql::Reconnect::ReconnectWithRetry
|
2
|
+
def reconnect!
|
3
|
+
Activerecord::Mysql::Reconnect.retryable(
|
4
|
+
:proc => proc { super },
|
5
|
+
:connection => @connection
|
6
|
+
)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
11
|
+
alias_method :reconnect_without_retry!, :reconnect!
|
12
|
+
prepend Activerecord::Mysql::Reconnect::ReconnectWithRetry
|
13
|
+
end
|