acts_as_ferret 0.4.8.2 → 0.5
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.
- data/README +2 -6
- data/bin/aaf_install +10 -6
- data/config/ferret_server.yml +2 -2
- data/doc/demo/app/models/stats.rb +1 -1
- data/lib/acts_as_ferret.rb +39 -37
- data/lib/{act_methods.rb → acts_as_ferret/act_methods.rb} +1 -1
- data/lib/{blank_slate.rb → acts_as_ferret/blank_slate.rb} +0 -0
- data/lib/{bulk_indexer.rb → acts_as_ferret/bulk_indexer.rb} +0 -0
- data/lib/{class_methods.rb → acts_as_ferret/class_methods.rb} +0 -0
- data/lib/{ferret_extensions.rb → acts_as_ferret/ferret_extensions.rb} +12 -16
- data/lib/{ferret_find_methods.rb → acts_as_ferret/ferret_find_methods.rb} +0 -0
- data/lib/{ferret_result.rb → acts_as_ferret/ferret_result.rb} +0 -0
- data/lib/{index.rb → acts_as_ferret/index.rb} +0 -0
- data/lib/{instance_methods.rb → acts_as_ferret/instance_methods.rb} +1 -1
- data/lib/{local_index.rb → acts_as_ferret/local_index.rb} +7 -4
- data/lib/{more_like_this.rb → acts_as_ferret/more_like_this.rb} +0 -0
- data/lib/{multi_index.rb → acts_as_ferret/multi_index.rb} +0 -0
- data/lib/acts_as_ferret/railtie.rb +16 -0
- data/lib/{rdig_adapter.rb → acts_as_ferret/rdig_adapter.rb} +0 -1
- data/lib/{remote_functions.rb → acts_as_ferret/remote_functions.rb} +0 -0
- data/lib/{remote_index.rb → acts_as_ferret/remote_index.rb} +0 -0
- data/lib/{remote_multi_index.rb → acts_as_ferret/remote_multi_index.rb} +0 -0
- data/lib/{search_results.rb → acts_as_ferret/search_results.rb} +0 -0
- data/lib/acts_as_ferret/server/config.rb +50 -0
- data/lib/{ferret_server.rb → acts_as_ferret/server/server.rb} +11 -56
- data/lib/{unix_daemon.rb → acts_as_ferret/server/unix_daemon.rb} +2 -4
- data/lib/acts_as_ferret/version.rb +3 -0
- data/lib/{without_ar.rb → acts_as_ferret/without_ar.rb} +0 -0
- data/recipes/aaf_recipes.rb +2 -4
- data/script/ferret_server +72 -6
- data/tasks/ferret.rake +13 -9
- metadata +68 -39
- data/acts_as_ferret.gemspec +0 -59
- data/init.rb +0 -24
- data/install.rb +0 -18
- data/lib/ar_mysql_auto_reconnect_patch.rb +0 -41
- data/lib/server_manager.rb +0 -71
- data/script/ferret_daemon +0 -94
- data/script/ferret_service +0 -178
@@ -1,8 +1,6 @@
|
|
1
|
-
################################################################################
|
2
1
|
module ActsAsFerret
|
3
|
-
module
|
2
|
+
module Server
|
4
3
|
|
5
|
-
################################################################################
|
6
4
|
# methods for becoming a daemon on Unix-like operating systems
|
7
5
|
module UnixDaemon
|
8
6
|
|
@@ -13,7 +11,7 @@ module ActsAsFerret
|
|
13
11
|
trap("TERM") { exit(0) }
|
14
12
|
sess_id = Process.setsid
|
15
13
|
STDIN.reopen("/dev/null")
|
16
|
-
STDOUT.reopen("#{
|
14
|
+
STDOUT.reopen("#{Rails.root}/log/ferret_server.out", "a")
|
17
15
|
STDERR.reopen(STDOUT)
|
18
16
|
block.call
|
19
17
|
end
|
File without changes
|
data/recipes/aaf_recipes.rb
CHANGED
@@ -46,15 +46,13 @@ namespace :ferret do
|
|
46
46
|
desc "Stop the Ferret DRb server"
|
47
47
|
task :stop, :roles => :app do
|
48
48
|
rails_env = fetch(:rails_env, 'production')
|
49
|
-
|
50
|
-
run "cd #{current_path}; #{ruby} script/ferret_server -e #{rails_env} stop || true"
|
49
|
+
run "cd #{current_path}; script/ferret_server -e #{rails_env} stop || true"
|
51
50
|
end
|
52
51
|
|
53
52
|
desc "Start the Ferret DRb server"
|
54
53
|
task :start, :roles => :app do
|
55
54
|
rails_env = fetch(:rails_env, 'production')
|
56
|
-
|
57
|
-
run "cd #{current_path}; #{ruby} script/ferret_server -e #{rails_env} start"
|
55
|
+
run "cd #{current_path}; script/ferret_server -e #{rails_env} start"
|
58
56
|
end
|
59
57
|
|
60
58
|
desc "Restart the Ferret DRb server"
|
data/script/ferret_server
CHANGED
@@ -2,11 +2,77 @@
|
|
2
2
|
|
3
3
|
FERRET_SERVER = File.expand_path(__FILE__)
|
4
4
|
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
$ferret_server_options = {
|
8
|
+
'environment' => nil,
|
9
|
+
'debug' => nil,
|
10
|
+
'root' => nil
|
11
|
+
}
|
12
|
+
|
13
|
+
OptionParser.new do |optparser|
|
14
|
+
optparser.banner = "Usage: #{FERRET_SERVER} [options] {start|stop|run}"
|
15
|
+
|
16
|
+
optparser.on('-h', '--help', "This message") do
|
17
|
+
puts optparser
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
|
21
|
+
optparser.on('-R', '--root=PATH', 'Set Rails.root to the given string') do |r|
|
22
|
+
$ferret_server_options['root'] = r
|
23
|
+
end
|
24
|
+
|
25
|
+
optparser.on('-e', '--environment=NAME', 'Set Rails.env to the given string') do |e|
|
26
|
+
$ferret_server_options['environment'] = e
|
27
|
+
end
|
28
|
+
|
29
|
+
optparser.on('--debug', 'Include full stack traces on exceptions') do
|
30
|
+
$ferret_server_options['debug'] = true
|
31
|
+
end
|
32
|
+
|
33
|
+
$ferret_server_action = optparser.permute!(ARGV)
|
34
|
+
(puts optparser; exit(1)) unless $ferret_server_action.size == 1
|
35
|
+
|
36
|
+
$ferret_server_action = $ferret_server_action.first
|
37
|
+
(puts optparser; exit(1)) unless %w(start stop run).include?($ferret_server_action)
|
38
|
+
end
|
39
|
+
|
40
|
+
################################################################################
|
41
|
+
|
42
|
+
def determine_rails_root
|
43
|
+
possible_rails_roots = [
|
44
|
+
$ferret_server_options['root'],
|
45
|
+
(defined?(FERRET_SERVER) ? File.join(File.dirname(FERRET_SERVER), '..') : nil),
|
46
|
+
File.join(File.dirname(__FILE__), *(['..']*4)),
|
47
|
+
'.'
|
48
|
+
].compact
|
49
|
+
# take the first dir where environment.rb can be found
|
50
|
+
possible_rails_roots.find{ |dir| File.readable?(File.join(dir, 'config', 'application.rb')) }
|
51
|
+
end
|
52
|
+
|
5
53
|
begin
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
54
|
+
ENV['FERRET_USE_LOCAL_INDEX'] = 'true'
|
55
|
+
if env = $ferret_server_options['environment']
|
56
|
+
ENV['RAILS_ENV'] = env
|
57
|
+
end
|
58
|
+
|
59
|
+
# determine RAILS_ROOT unless already set
|
60
|
+
root = File.expand_path(determine_rails_root)
|
61
|
+
|
62
|
+
begin
|
63
|
+
require File.join(root, 'config', 'application')
|
64
|
+
rescue
|
65
|
+
puts "Error booting your rails app at #{root}: #{$!}\n#{$!.backtrace.join("\n")}"
|
66
|
+
raise $!
|
67
|
+
end
|
68
|
+
|
69
|
+
puts "Rails.root: #{Rails.root}"
|
70
|
+
puts "Rails.env: #{Rails.env}"
|
71
|
+
|
72
|
+
require 'acts_as_ferret/server/server'
|
73
|
+
ActsAsFerret::Server::Server.new.send($ferret_server_action)
|
74
|
+
rescue Exception => e
|
75
|
+
$stderr.puts(e.message)
|
76
|
+
$stderr.puts(e.backtrace.join("\n")) if $ferret_server_options['debug']
|
77
|
+
exit(1)
|
12
78
|
end
|
data/tasks/ferret.rake
CHANGED
@@ -6,17 +6,21 @@ namespace :ferret do
|
|
6
6
|
# INDEXES="my_model shared" rake ferret:rebuild
|
7
7
|
desc "Rebuild a Ferret index. Specify what model to rebuild with the INDEXES environment variable."
|
8
8
|
task :rebuild => :environment do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
object
|
9
|
+
if ENV['INDEXES']
|
10
|
+
indexes = ENV['INDEXES'].split
|
11
|
+
indexes.each do |index_name|
|
12
|
+
start = 1.minute.ago
|
13
|
+
ActsAsFerret::rebuild_index index_name
|
14
|
+
idx = ActsAsFerret::get_index index_name
|
15
|
+
# update records that have changed since the rebuild started
|
16
|
+
idx.index_definition[:registered_models].each do |m|
|
17
|
+
m.records_modified_since(start).each do |object|
|
18
|
+
object.ferret_update
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
22
|
+
else
|
23
|
+
puts "set the INDEXES environment variable to the index names you want to rebuild:\nINDEXES=\"my_index another_index\" rake ferret:rebuild"
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_ferret
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 5
|
8
|
+
version: "0.5"
|
5
9
|
platform: ruby
|
6
10
|
authors:
|
7
11
|
- Jens Kraemer
|
@@ -9,19 +13,38 @@ autorequire:
|
|
9
13
|
bindir: bin
|
10
14
|
cert_chain: []
|
11
15
|
|
12
|
-
date: 2010-
|
16
|
+
date: 2010-09-07 00:00:00 +02:00
|
13
17
|
default_executable: aaf_install
|
14
18
|
dependencies:
|
15
19
|
- !ruby/object:Gem::Dependency
|
16
20
|
name: jk-ferret
|
17
|
-
|
18
|
-
|
19
|
-
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 11
|
30
|
+
- 8
|
23
31
|
version: 0.11.8
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rails
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 3
|
44
|
+
- 0
|
45
|
+
version: "3.0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
25
48
|
description: Rails plugin that adds powerful full text search capabilities to ActiveRecord models.
|
26
49
|
email: jk@jkraemer.net
|
27
50
|
executables:
|
@@ -32,6 +55,8 @@ extra_rdoc_files:
|
|
32
55
|
- LICENSE
|
33
56
|
- README
|
34
57
|
files:
|
58
|
+
- README
|
59
|
+
- LICENSE
|
35
60
|
- bin/aaf_install
|
36
61
|
- config/ferret_server.yml
|
37
62
|
- doc/README.win32
|
@@ -161,38 +186,32 @@ files:
|
|
161
186
|
- doc/demo/vendor/plugins/will_paginate/test/pagination_test.rb
|
162
187
|
- doc/monit-example
|
163
188
|
- recipes/aaf_recipes.rb
|
164
|
-
- script/ferret_daemon
|
165
189
|
- script/ferret_server
|
166
|
-
- script/ferret_service
|
167
190
|
- tasks/ferret.rake
|
168
|
-
- lib/act_methods.rb
|
191
|
+
- lib/acts_as_ferret/act_methods.rb
|
192
|
+
- lib/acts_as_ferret/blank_slate.rb
|
193
|
+
- lib/acts_as_ferret/bulk_indexer.rb
|
194
|
+
- lib/acts_as_ferret/class_methods.rb
|
195
|
+
- lib/acts_as_ferret/ferret_extensions.rb
|
196
|
+
- lib/acts_as_ferret/ferret_find_methods.rb
|
197
|
+
- lib/acts_as_ferret/ferret_result.rb
|
198
|
+
- lib/acts_as_ferret/index.rb
|
199
|
+
- lib/acts_as_ferret/instance_methods.rb
|
200
|
+
- lib/acts_as_ferret/local_index.rb
|
201
|
+
- lib/acts_as_ferret/more_like_this.rb
|
202
|
+
- lib/acts_as_ferret/multi_index.rb
|
203
|
+
- lib/acts_as_ferret/railtie.rb
|
204
|
+
- lib/acts_as_ferret/rdig_adapter.rb
|
205
|
+
- lib/acts_as_ferret/remote_functions.rb
|
206
|
+
- lib/acts_as_ferret/remote_index.rb
|
207
|
+
- lib/acts_as_ferret/remote_multi_index.rb
|
208
|
+
- lib/acts_as_ferret/search_results.rb
|
209
|
+
- lib/acts_as_ferret/server/config.rb
|
210
|
+
- lib/acts_as_ferret/server/server.rb
|
211
|
+
- lib/acts_as_ferret/server/unix_daemon.rb
|
212
|
+
- lib/acts_as_ferret/version.rb
|
213
|
+
- lib/acts_as_ferret/without_ar.rb
|
169
214
|
- lib/acts_as_ferret.rb
|
170
|
-
- lib/ar_mysql_auto_reconnect_patch.rb
|
171
|
-
- lib/blank_slate.rb
|
172
|
-
- lib/bulk_indexer.rb
|
173
|
-
- lib/class_methods.rb
|
174
|
-
- lib/ferret_extensions.rb
|
175
|
-
- lib/ferret_find_methods.rb
|
176
|
-
- lib/ferret_result.rb
|
177
|
-
- lib/ferret_server.rb
|
178
|
-
- lib/index.rb
|
179
|
-
- lib/instance_methods.rb
|
180
|
-
- lib/local_index.rb
|
181
|
-
- lib/more_like_this.rb
|
182
|
-
- lib/multi_index.rb
|
183
|
-
- lib/rdig_adapter.rb
|
184
|
-
- lib/remote_functions.rb
|
185
|
-
- lib/remote_index.rb
|
186
|
-
- lib/remote_multi_index.rb
|
187
|
-
- lib/search_results.rb
|
188
|
-
- lib/server_manager.rb
|
189
|
-
- lib/unix_daemon.rb
|
190
|
-
- lib/without_ar.rb
|
191
|
-
- acts_as_ferret.gemspec
|
192
|
-
- init.rb
|
193
|
-
- install.rb
|
194
|
-
- README
|
195
|
-
- LICENSE
|
196
215
|
has_rdoc: true
|
197
216
|
homepage: http://github.com/jkraemer/acts_as_ferret
|
198
217
|
licenses: []
|
@@ -200,24 +219,34 @@ licenses: []
|
|
200
219
|
post_install_message:
|
201
220
|
rdoc_options:
|
202
221
|
- --charset=UTF-8
|
222
|
+
- --title
|
223
|
+
- ActsAsFeret - Ferret powered full text search for Rails
|
224
|
+
- --main
|
225
|
+
- README
|
203
226
|
require_paths:
|
204
227
|
- lib
|
205
228
|
required_ruby_version: !ruby/object:Gem::Requirement
|
229
|
+
none: false
|
206
230
|
requirements:
|
207
231
|
- - ">="
|
208
232
|
- !ruby/object:Gem::Version
|
209
|
-
|
210
|
-
|
233
|
+
segments:
|
234
|
+
- 1
|
235
|
+
- 8
|
236
|
+
- 7
|
237
|
+
version: 1.8.7
|
211
238
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
239
|
+
none: false
|
212
240
|
requirements:
|
213
241
|
- - ">="
|
214
242
|
- !ruby/object:Gem::Version
|
243
|
+
segments:
|
244
|
+
- 0
|
215
245
|
version: "0"
|
216
|
-
version:
|
217
246
|
requirements: []
|
218
247
|
|
219
248
|
rubyforge_project: acts_as_ferret
|
220
|
-
rubygems_version: 1.3.
|
249
|
+
rubygems_version: 1.3.7
|
221
250
|
signing_key:
|
222
251
|
specification_version: 3
|
223
252
|
summary: acts_as_ferret - Ferret based full text search for any ActiveRecord model
|
data/acts_as_ferret.gemspec
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
|
3
|
-
s.name = 'acts_as_ferret'
|
4
|
-
s.version = '0.4.8.2'
|
5
|
-
s.authors = ['Jens Kraemer']
|
6
|
-
s.summary = 'acts_as_ferret - Ferret based full text search for any ActiveRecord model'
|
7
|
-
s.description = 'Rails plugin that adds powerful full text search capabilities to ActiveRecord models.'
|
8
|
-
s.email = 'jk@jkraemer.net'
|
9
|
-
s.homepage = 'http://github.com/jkraemer/acts_as_ferret'
|
10
|
-
s.rubyforge_project = 'acts_as_ferret'
|
11
|
-
|
12
|
-
s.bindir = 'bin'
|
13
|
-
s.executables = ['aaf_install']
|
14
|
-
s.default_executable = 'aaf_install'
|
15
|
-
s.require_paths = ["lib"]
|
16
|
-
|
17
|
-
|
18
|
-
s.platform = Gem::Platform::RUBY
|
19
|
-
s.required_ruby_version = '>=1.8.6'
|
20
|
-
s.rubygems_version = '1.3.6'
|
21
|
-
if s.respond_to? :specification_version then
|
22
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
-
s.specification_version = 3
|
24
|
-
|
25
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
-
s.add_runtime_dependency('jk-ferret', [">= 0.11.8"])
|
27
|
-
else
|
28
|
-
s.add_dependency('jk-ferret', [">= 0.11.8"])
|
29
|
-
end
|
30
|
-
else
|
31
|
-
s.add_dependency('jk-ferret', [">= 0.11.8"])
|
32
|
-
end
|
33
|
-
|
34
|
-
|
35
|
-
s.has_rdoc = true
|
36
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
-
s.extra_rdoc_files = [
|
38
|
-
'LICENSE',
|
39
|
-
'README'
|
40
|
-
]
|
41
|
-
s.test_files = Dir['test/**/*rb']
|
42
|
-
s.files = [
|
43
|
-
'bin/*',
|
44
|
-
'config/*',
|
45
|
-
'doc/**/*',
|
46
|
-
'recipes/*',
|
47
|
-
'script/*',
|
48
|
-
'tasks/*',
|
49
|
-
'lib/**/*rb'
|
50
|
-
].map{|p| Dir[p]}.flatten +
|
51
|
-
[
|
52
|
-
'acts_as_ferret.gemspec',
|
53
|
-
'init.rb',
|
54
|
-
'install.rb',
|
55
|
-
'README',
|
56
|
-
'LICENSE',
|
57
|
-
]
|
58
|
-
|
59
|
-
end
|
data/init.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# Copyright (c) 2006 Kasper Weibel Nielsen-Refs, Thomas Lockney, Jens Krämer
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in all
|
11
|
-
# copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
# SOFTWARE.
|
20
|
-
|
21
|
-
require 'acts_as_ferret'
|
22
|
-
|
23
|
-
config.after_initialize { ActsAsFerret::load_config }
|
24
|
-
config.to_prepare { ActsAsFerret::load_config }
|
data/install.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# acts_as_ferret install script
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
def install(file)
|
5
|
-
puts "Installing: #{file}"
|
6
|
-
target = File.join(File.dirname(__FILE__), '..', '..', '..', file)
|
7
|
-
if File.exists?(target)
|
8
|
-
puts "target #{target} already exists, skipping"
|
9
|
-
else
|
10
|
-
FileUtils.cp File.join(File.dirname(__FILE__), file), target
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
install File.join( 'script', 'ferret_server' )
|
15
|
-
install File.join( 'config', 'ferret_server.yml' )
|
16
|
-
|
17
|
-
puts IO.read(File.join(File.dirname(__FILE__), 'README'))
|
18
|
-
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# Source: http://pastie.caboo.se/154842
|
2
|
-
#
|
3
|
-
# in /etc/my.cnf on the MySQL server, you can set the interactive-timeout parameter,
|
4
|
-
# for example, 12 hours = 28800 sec
|
5
|
-
# interactive-timeout=28800
|
6
|
-
|
7
|
-
# in ActiveRecord, setting the verification_timeout to something less than
|
8
|
-
# the interactive-timeout parameter; 14400 sec = 6 hours
|
9
|
-
ActiveRecord::Base.verification_timeout = 14400
|
10
|
-
ActiveRecord::Base.establish_connection
|
11
|
-
|
12
|
-
# Below is a monkey patch for keeping ActiveRecord connections alive.
|
13
|
-
# http://www.sparecycles.org/2007/7/2/saying-goodbye-to-lost-connections-in-rails
|
14
|
-
|
15
|
-
module ActiveRecord
|
16
|
-
module ConnectionAdapters
|
17
|
-
class MysqlAdapter
|
18
|
-
def execute(sql, name = nil) #:nodoc:
|
19
|
-
reconnect_lost_connections = true
|
20
|
-
begin
|
21
|
-
log(sql, name) { @connection.query(sql) }
|
22
|
-
rescue ActiveRecord::StatementInvalid => exception
|
23
|
-
if reconnect_lost_connections and exception.message =~ /(Lost connection to MySQL server during query
|
24
|
-
|MySQL server has gone away)/
|
25
|
-
reconnect_lost_connections = false
|
26
|
-
reconnect!
|
27
|
-
retry
|
28
|
-
elsif exception.message.split(":").first =~ /Packets out of order/
|
29
|
-
raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database.
|
30
|
-
Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hash
|
31
|
-
ing.html for more information. If you're on Windows, use the Instant Rails installer to get the updated mysql
|
32
|
-
bindings."
|
33
|
-
else
|
34
|
-
raise
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|