sunspot 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 1.3.2
|
2
|
+
|
3
|
+
* Set initialization order for Railtie (Mauro)
|
4
|
+
* Removes deprecated `InstanceMethods` module (Anders Bengtsson)
|
5
|
+
* Adds `Retry5xxSessionProxy` to retry requests when an internal server error
|
6
|
+
occurs (Nick Zadrozny)
|
7
|
+
|
1
8
|
== 1.3.0 2011-11-26
|
2
9
|
* Requests to Solr use HTTP POST verb by default to avoid issues when the query string grows too large for GET (Johan Van Ryseghem)
|
3
10
|
* `sunspot.yml` supports ERB (Andrew Cholakian)
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'abstract_session_proxy')
|
2
|
+
|
3
|
+
module Sunspot
|
4
|
+
module SessionProxy
|
5
|
+
class Retry5xxSessionProxy < AbstractSessionProxy
|
6
|
+
|
7
|
+
class RetryHandler
|
8
|
+
attr_reader :search_session
|
9
|
+
|
10
|
+
def initialize(search_session)
|
11
|
+
@search_session = search_session
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(m, *args, &block)
|
15
|
+
retry_count = 1
|
16
|
+
begin
|
17
|
+
search_session.send(m, *args, &block)
|
18
|
+
rescue Errno::ECONNRESET => e
|
19
|
+
if retry_count > 0
|
20
|
+
$stderr.puts "Error - #{e.message[/^.*$/]} - retrying..."
|
21
|
+
retry_count -= 1
|
22
|
+
retry
|
23
|
+
else
|
24
|
+
$stderr.puts "Error - #{e.message[/^.*$/]} - ignoring..."
|
25
|
+
end
|
26
|
+
rescue RSolr::Error::Http => e
|
27
|
+
if (500..599).include?(e.response[:status].to_i)
|
28
|
+
if retry_count > 0
|
29
|
+
$stderr.puts "Error - #{e.message[/^.*$/]} - retrying..."
|
30
|
+
retry_count -= 1
|
31
|
+
retry
|
32
|
+
else
|
33
|
+
$stderr.puts "Error - #{e.message[/^.*$/]} - ignoring..."
|
34
|
+
e.response
|
35
|
+
end
|
36
|
+
else
|
37
|
+
raise e
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
attr_reader :search_session
|
44
|
+
attr_reader :retry_handler
|
45
|
+
|
46
|
+
delegate :new_search, :search, :config,
|
47
|
+
:new_more_like_this, :more_like_this,
|
48
|
+
:delete_dirty, :delete_dirty?,
|
49
|
+
:to => :search_session
|
50
|
+
|
51
|
+
def initialize(search_session = Sunspot.session)
|
52
|
+
@search_session = search_session
|
53
|
+
@retry_handler = RetryHandler.new(search_session)
|
54
|
+
end
|
55
|
+
|
56
|
+
def rescued_exception(method, e)
|
57
|
+
$stderr.puts("Exception in #{method}: #{e.message}")
|
58
|
+
end
|
59
|
+
|
60
|
+
delegate :batch, :commit, :commit_if_dirty, :commit_if_delete_dirty,
|
61
|
+
:dirty?, :index!, :index, :optimize, :remove!, :remove, :remove_all!,
|
62
|
+
:remove_all, :remove_by_id!, :remove_by_id,
|
63
|
+
:to => :retry_handler
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/sunspot/version.rb
CHANGED
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe Sunspot::SessionProxy::Retry5xxSessionProxy do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
Sunspot::Session.connection_class = Mock::ConnectionFactory.new
|
7
|
+
@sunspot_session = Sunspot.session
|
8
|
+
@proxy = Sunspot::SessionProxy::Retry5xxSessionProxy.new(@sunspot_session)
|
9
|
+
Sunspot.session = @proxy
|
10
|
+
end
|
11
|
+
|
12
|
+
class FakeRSolrErrorHttp < RSolr::Error::Http
|
13
|
+
def backtrace
|
14
|
+
[]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
let :fake_rsolr_request do
|
19
|
+
{:uri => 'http://solr.test/uri'}
|
20
|
+
end
|
21
|
+
|
22
|
+
def fake_rsolr_response(status)
|
23
|
+
{:status => status.to_s}
|
24
|
+
end
|
25
|
+
|
26
|
+
let :post do
|
27
|
+
Post.new(:title => 'test')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should behave normally without a stubbed exception" do
|
31
|
+
@sunspot_session.should_receive(:index).and_return(mock)
|
32
|
+
Sunspot.index(post)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be successful with a single exception followed by a sucess" do
|
36
|
+
e = FakeRSolrErrorHttp.new(fake_rsolr_request, fake_rsolr_response(503))
|
37
|
+
@sunspot_session.should_receive(:index).and_return do
|
38
|
+
@sunspot_session.should_receive(:index).and_return(mock)
|
39
|
+
raise e
|
40
|
+
end
|
41
|
+
Sunspot.index(post)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return the error response after two exceptions" do
|
45
|
+
fake_response = fake_rsolr_response(503)
|
46
|
+
e = FakeRSolrErrorHttp.new(fake_rsolr_request, fake_response)
|
47
|
+
fake_success = mock('success')
|
48
|
+
|
49
|
+
@sunspot_session.should_receive(:index).and_return do
|
50
|
+
@sunspot_session.should_receive(:index).and_return do
|
51
|
+
@sunspot_session.stub!(:index).and_return(fake_success)
|
52
|
+
raise e
|
53
|
+
end
|
54
|
+
raise e
|
55
|
+
end
|
56
|
+
|
57
|
+
response = Sunspot.index(post)
|
58
|
+
response.should_not == fake_success
|
59
|
+
response.should == fake_response
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not retry a 4xx" do
|
63
|
+
e = FakeRSolrErrorHttp.new(fake_rsolr_request, fake_rsolr_response(400))
|
64
|
+
@sunspot_session.should_receive(:index).and_raise(e)
|
65
|
+
lambda { Sunspot.index(post) }.should raise_error
|
66
|
+
end
|
67
|
+
|
68
|
+
# TODO: try against more than just Sunspot.index? but that's just testing the
|
69
|
+
# invocation of delegate, so probably not important. -nz 11Apr12
|
70
|
+
|
71
|
+
it_should_behave_like 'session proxy'
|
72
|
+
|
73
|
+
end
|
data/sunspot.gemspec
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 1.3.
|
8
|
+
- 2
|
9
|
+
version: 1.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mat Brown
|
@@ -32,7 +32,7 @@ autorequire:
|
|
32
32
|
bindir: bin
|
33
33
|
cert_chain: []
|
34
34
|
|
35
|
-
date: 2012-
|
35
|
+
date: 2012-05-13 00:00:00 -07:00
|
36
36
|
default_executable:
|
37
37
|
dependencies:
|
38
38
|
- !ruby/object:Gem::Dependency
|
@@ -49,24 +49,10 @@ dependencies:
|
|
49
49
|
version: 1.0.7
|
50
50
|
type: :runtime
|
51
51
|
version_requirements: *id001
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
name: escape
|
54
|
-
prerelease: false
|
55
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
56
|
-
requirements:
|
57
|
-
- - ~>
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
segments:
|
60
|
-
- 0
|
61
|
-
- 0
|
62
|
-
- 4
|
63
|
-
version: 0.0.4
|
64
|
-
type: :runtime
|
65
|
-
version_requirements: *id002
|
66
52
|
- !ruby/object:Gem::Dependency
|
67
53
|
name: pr_geohash
|
68
54
|
prerelease: false
|
69
|
-
requirement: &
|
55
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
70
56
|
requirements:
|
71
57
|
- - ~>
|
72
58
|
- !ruby/object:Gem::Version
|
@@ -75,11 +61,11 @@ dependencies:
|
|
75
61
|
- 0
|
76
62
|
version: "1.0"
|
77
63
|
type: :runtime
|
78
|
-
version_requirements: *
|
64
|
+
version_requirements: *id002
|
79
65
|
- !ruby/object:Gem::Dependency
|
80
66
|
name: rspec
|
81
67
|
prerelease: false
|
82
|
-
requirement: &
|
68
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
83
69
|
requirements:
|
84
70
|
- - ~>
|
85
71
|
- !ruby/object:Gem::Version
|
@@ -89,11 +75,11 @@ dependencies:
|
|
89
75
|
- 0
|
90
76
|
version: 2.6.0
|
91
77
|
type: :development
|
92
|
-
version_requirements: *
|
78
|
+
version_requirements: *id003
|
93
79
|
- !ruby/object:Gem::Dependency
|
94
80
|
name: hanna
|
95
81
|
prerelease: false
|
96
|
-
requirement: &
|
82
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
97
83
|
requirements:
|
98
84
|
- - ">="
|
99
85
|
- !ruby/object:Gem::Version
|
@@ -101,7 +87,7 @@ dependencies:
|
|
101
87
|
- 0
|
102
88
|
version: "0"
|
103
89
|
type: :development
|
104
|
-
version_requirements: *
|
90
|
+
version_requirements: *id004
|
105
91
|
description: " Sunspot is a library providing a powerful, all-ruby API for the Solr search engine. Sunspot manages the configuration of persistent\n Ruby classes for search and indexing and exposes Solr's most powerful features through a collection of DSLs. Complex search operations\n can be performed without hand-writing any boolean queries or building Solr parameters by hand.\n"
|
106
92
|
email:
|
107
93
|
- mat@patch.com
|
@@ -184,6 +170,7 @@ files:
|
|
184
170
|
- lib/sunspot/session_proxy/class_sharding_session_proxy.rb
|
185
171
|
- lib/sunspot/session_proxy/id_sharding_session_proxy.rb
|
186
172
|
- lib/sunspot/session_proxy/master_slave_session_proxy.rb
|
173
|
+
- lib/sunspot/session_proxy/retry_5xx_session_proxy.rb
|
187
174
|
- lib/sunspot/session_proxy/sharding_session_proxy.rb
|
188
175
|
- lib/sunspot/session_proxy/silent_fail_session_proxy.rb
|
189
176
|
- lib/sunspot/session_proxy/thread_local_session_proxy.rb
|
@@ -233,6 +220,7 @@ files:
|
|
233
220
|
- spec/api/session_proxy/class_sharding_session_proxy_spec.rb
|
234
221
|
- spec/api/session_proxy/id_sharding_session_proxy_spec.rb
|
235
222
|
- spec/api/session_proxy/master_slave_session_proxy_spec.rb
|
223
|
+
- spec/api/session_proxy/retry_5xx_session_proxy_spec.rb
|
236
224
|
- spec/api/session_proxy/sharding_session_proxy_spec.rb
|
237
225
|
- spec/api/session_proxy/silent_fail_session_proxy_spec.rb
|
238
226
|
- spec/api/session_proxy/spec_helper.rb
|
@@ -347,6 +335,7 @@ test_files:
|
|
347
335
|
- spec/api/session_proxy/class_sharding_session_proxy_spec.rb
|
348
336
|
- spec/api/session_proxy/id_sharding_session_proxy_spec.rb
|
349
337
|
- spec/api/session_proxy/master_slave_session_proxy_spec.rb
|
338
|
+
- spec/api/session_proxy/retry_5xx_session_proxy_spec.rb
|
350
339
|
- spec/api/session_proxy/sharding_session_proxy_spec.rb
|
351
340
|
- spec/api/session_proxy/silent_fail_session_proxy_spec.rb
|
352
341
|
- spec/api/session_proxy/spec_helper.rb
|