activerecord-mysql-reconnect 0.2.0 → 0.2.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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b2336f22ee2714c4d2d6d87ddd61d5487b15c40
|
4
|
+
data.tar.gz: d6f2eeb31a54a091eba165db2c0e8586c9452902
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd60c8b113f3c3bfe4f5244deb1c51ddca613b356400f15bee03dbbc1f4c4f08a9e817b2a8773a5d0b0e01be8ac80272adea31697e533ed8373819ba2ccd0a44
|
7
|
+
data.tar.gz: a4b643b0554b0ee64c51c5e04288ce41033800a38f7bcd9ed020b1b16706a15be673c03fc98cb2a7e1d9b2d6a5c6fe397408789e1915b12d2139549b4e64be38
|
data/README.md
CHANGED
@@ -34,6 +34,7 @@ ActiveRecord::Base.establish_connection(
|
|
34
34
|
|
35
35
|
ActiveRecord::Base.logger = Logger.new($stdout)
|
36
36
|
ActiveRecord::Base.logger.formatter = proc {|_, _, _, message| "#{message}\n" }
|
37
|
+
ActiveRecord::Base.enable_retry = true
|
37
38
|
ActiveRecord::Base.execution_tries = 3
|
38
39
|
|
39
40
|
class Employee < ActiveRecord::Base; end
|
@@ -87,6 +88,7 @@ gem 'activerecord-mysql-reconnect'
|
|
87
88
|
```ruby
|
88
89
|
MyApp::Application.configure do
|
89
90
|
...
|
91
|
+
config.active_record.enable_retry = true
|
90
92
|
config.active_record.execution_tries = 10 # times
|
91
93
|
config.active_record.execution_retry_wait = 1.5 # sec
|
92
94
|
...
|
@@ -47,6 +47,10 @@ module Activerecord::Mysql::Reconnect
|
|
47
47
|
ActiveRecord::Base.execution_retry_wait || DEFAULT_EXECUTION_RETRY_WAIT
|
48
48
|
end
|
49
49
|
|
50
|
+
def enable_retry
|
51
|
+
!!ActiveRecord::Base.enable_retry
|
52
|
+
end
|
53
|
+
|
50
54
|
def retryable(opts)
|
51
55
|
block = opts.fetch(:proc)
|
52
56
|
on_error = opts[:on_error]
|
@@ -58,7 +62,7 @@ module Activerecord::Mysql::Reconnect
|
|
58
62
|
retval = block.call
|
59
63
|
break
|
60
64
|
rescue => e
|
61
|
-
if (tries.zero? or n < tries) and should_handle?(e)
|
65
|
+
if enable_retry and (tries.zero? or n < tries) and should_handle?(e)
|
62
66
|
on_error.call if on_error
|
63
67
|
wait = self.execution_retry_wait * n
|
64
68
|
logger.warn("MySQL server has gone away. Trying to reconnect in #{wait} seconds. (cause: #{e} [#{e.class}])")
|
@@ -213,4 +213,23 @@ describe 'activerecord-mysql-reconnect' do
|
|
213
213
|
th.join
|
214
214
|
}.to_not raise_error
|
215
215
|
end
|
216
|
+
|
217
|
+
it 'disable reconnect' do
|
218
|
+
expect {
|
219
|
+
begin
|
220
|
+
ActiveRecord::Base.enable_retry = false
|
221
|
+
expect(Employee.all.length).to eq(300024)
|
222
|
+
mysql_restart
|
223
|
+
expect(Employee.all.length).to eq(300024)
|
224
|
+
ensure
|
225
|
+
ActiveRecord::Base.enable_retry = true
|
226
|
+
end
|
227
|
+
}.to raise_error(ActiveRecord::StatementInvalid)
|
228
|
+
|
229
|
+
expect {
|
230
|
+
expect(Employee.all.length).to eq(300024)
|
231
|
+
mysql_restart
|
232
|
+
expect(Employee.all.length).to eq(300024)
|
233
|
+
}.to_not raise_error
|
234
|
+
end
|
216
235
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -36,6 +36,7 @@ RSpec.configure do |config|
|
|
36
36
|
|
37
37
|
ActiveRecord::Base.logger = Logger.new($stdout)
|
38
38
|
ActiveRecord::Base.logger.formatter = proc {|_, _, _, message| "#{message}\n" }
|
39
|
+
ActiveRecord::Base.enable_retry = true
|
39
40
|
ActiveRecord::Base.execution_tries = 10
|
40
41
|
end
|
41
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-mysql-reconnect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|