sunspot-queue 0.9.0 → 0.9.1
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.md +16 -1
- data/lib/sunspot/queue.rb +1 -2
- data/lib/sunspot/queue/helpers.rb +6 -9
- data/lib/sunspot/queue/index_job.rb +1 -3
- data/lib/sunspot/queue/version.rb +5 -0
- data/spec/index_job_spec.rb +13 -0
- data/spec/integration/indexing_spec.rb +13 -5
- data/spec/removal_job_spec.rb +4 -3
- data/spec/spec_helper.rb +10 -0
- metadata +3 -24
data/README.md
CHANGED
@@ -6,6 +6,21 @@ Background search indexing using existing worker systems.
|
|
6
6
|
|
7
7
|
$ gem install sunspot-queue
|
8
8
|
|
9
|
+
## Usage with Rails (or without)
|
10
|
+
|
11
|
+
In your Gemfile
|
12
|
+
|
13
|
+
gem "sunspot-queue"
|
14
|
+
gem "resque"
|
15
|
+
|
16
|
+
In config/initializers/sunspot.rb
|
17
|
+
|
18
|
+
Sunspot.session = Sunspot::Queue::SessionProxy.new(Sunspot.session)
|
19
|
+
|
20
|
+
Start Resque
|
21
|
+
|
22
|
+
$ QUEUE=sunspot rake resque:work
|
23
|
+
|
9
24
|
## Note on Patches/Pull Requests
|
10
25
|
|
11
26
|
* Fork the project.
|
@@ -13,7 +28,7 @@ Background search indexing using existing worker systems.
|
|
13
28
|
* Make your feature addition or bug fix.
|
14
29
|
* Send me a pull request. Bonus points for topic branches.
|
15
30
|
|
16
|
-
Please don't make changes to the Rakefile, version, or history.
|
31
|
+
Please don't make changes to the Rakefile, version, or history.
|
17
32
|
|
18
33
|
## Development
|
19
34
|
|
data/lib/sunspot/queue.rb
CHANGED
@@ -2,11 +2,10 @@ module Sunspot
|
|
2
2
|
module Queue
|
3
3
|
class Error < StandardError; end
|
4
4
|
class NotPersistedError < Error; end
|
5
|
-
|
6
|
-
VERSION = "0.9.0"
|
7
5
|
end
|
8
6
|
end
|
9
7
|
|
8
|
+
require "sunspot/queue/version"
|
10
9
|
require "sunspot/queue/session_proxy"
|
11
10
|
require "sunspot/queue/index_job"
|
12
11
|
require "sunspot/queue/removal_job"
|
@@ -3,21 +3,18 @@ require "sunspot/queue/session_proxy"
|
|
3
3
|
module Sunspot::Queue
|
4
4
|
module Helpers
|
5
5
|
def without_proxy
|
6
|
+
proxy = nil
|
7
|
+
|
6
8
|
# Pop off the queueing proxy for the block if it's in place so we don't
|
7
9
|
# requeue the same job multiple times.
|
8
10
|
if Sunspot.session.instance_of?(SessionProxy)
|
9
11
|
proxy = Sunspot.session
|
10
12
|
Sunspot.session = proxy.session
|
11
|
-
|
12
|
-
begin
|
13
|
-
yield
|
14
|
-
ensure
|
15
|
-
Sunspot.commit rescue nil
|
16
|
-
Sunspot.session = proxy
|
17
|
-
end
|
18
|
-
else
|
19
|
-
yield
|
20
13
|
end
|
14
|
+
|
15
|
+
yield
|
16
|
+
ensure
|
17
|
+
Sunspot.session = proxy if proxy
|
21
18
|
end
|
22
19
|
end
|
23
20
|
end
|
data/spec/index_job_spec.rb
CHANGED
@@ -8,6 +8,7 @@ describe Sunspot::Queue::IndexJob do
|
|
8
8
|
|
9
9
|
expect do
|
10
10
|
Sunspot::Queue::IndexJob.perform(Person, person.id)
|
11
|
+
commit
|
11
12
|
end.to change { Person.search.hits.size }.by(1)
|
12
13
|
|
13
14
|
results = Person.search { fulltext "grandson" }.results
|
@@ -25,5 +26,17 @@ describe Sunspot::Queue::IndexJob do
|
|
25
26
|
Sunspot::Queue::IndexJob.perform(Person, 404) rescue nil
|
26
27
|
end.to_not change { Sunspot.session }
|
27
28
|
end
|
29
|
+
|
30
|
+
it "does not commit changes to the index" do
|
31
|
+
person = Person.create(:name => "The Grandson")
|
32
|
+
|
33
|
+
expect do
|
34
|
+
Sunspot::Queue::IndexJob.perform(Person, person.id)
|
35
|
+
end.to_not change { Person.search.hits.size }
|
36
|
+
|
37
|
+
expect do
|
38
|
+
commit
|
39
|
+
end.to change { Person.search.hits.size }
|
40
|
+
end
|
28
41
|
end
|
29
42
|
end
|
@@ -1,21 +1,23 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
require "sunspot/queue/helpers"
|
3
2
|
|
4
3
|
describe "Queued Indexing" do
|
5
|
-
include Sunspot::Queue::Helpers
|
6
|
-
|
7
4
|
# Given an active record model
|
8
5
|
# When I save the model
|
9
6
|
# Then the record should not be in solr
|
7
|
+
# And a job should be enqueued in resque
|
10
8
|
#
|
11
9
|
# When resque jobs are run
|
10
|
+
# And the sunspot queue has been committed
|
12
11
|
# Then the record should be in solr
|
13
12
|
it "queues indexing of ActiveRecord models using resque" do
|
14
13
|
person = Person.create(:name => "Inigo Montoya")
|
15
14
|
Person.search.results.should be_empty
|
16
15
|
|
16
|
+
ResqueSpec.queue_by_name(:sunspot).size.should == 1
|
17
|
+
|
17
18
|
expect do
|
18
19
|
ResqueSpec.perform_all(:sunspot)
|
20
|
+
commit
|
19
21
|
end.to change { Person.search.hits.size }.by(1)
|
20
22
|
|
21
23
|
results = Person.search { fulltext "Montoya" }.results
|
@@ -29,8 +31,13 @@ describe "Queued Indexing" do
|
|
29
31
|
# When resque jobs are run
|
30
32
|
# Then the record should not be in solr
|
31
33
|
it "queues removal of ActiveRecord models using Resque" do
|
32
|
-
person =
|
33
|
-
|
34
|
+
person =
|
35
|
+
without_proxy do
|
36
|
+
Person.create(:name => "Fezzik").tap do
|
37
|
+
commit
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
34
41
|
Person.search.hits.size.should == 1
|
35
42
|
|
36
43
|
expect do
|
@@ -39,6 +46,7 @@ describe "Queued Indexing" do
|
|
39
46
|
|
40
47
|
expect do
|
41
48
|
ResqueSpec.perform_all(:sunspot)
|
49
|
+
commit
|
42
50
|
end.to change { Person.search.hits.size }.by(-1)
|
43
51
|
end
|
44
52
|
end
|
data/spec/removal_job_spec.rb
CHANGED
@@ -2,18 +2,19 @@ require "spec_helper"
|
|
2
2
|
require "sunspot/queue/helpers"
|
3
3
|
|
4
4
|
describe Sunspot::Queue::IndexJob do
|
5
|
-
include Sunspot::Queue::Helpers
|
6
|
-
|
7
5
|
it "removes a job from the search index" do
|
8
6
|
person =
|
9
7
|
without_proxy do
|
10
|
-
Person.create(:name => "The Albino")
|
8
|
+
Person.create(:name => "The Albino").tap do
|
9
|
+
commit
|
10
|
+
end
|
11
11
|
end
|
12
12
|
|
13
13
|
Person.search.hits.size.should == 1
|
14
14
|
|
15
15
|
expect do
|
16
16
|
Sunspot::Queue::RemovalJob.perform(Person, person.id)
|
17
|
+
commit
|
17
18
|
end.to change { Person.search.hits.size }.by(-1)
|
18
19
|
end
|
19
20
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "sunspot/queue"
|
2
|
+
require "sunspot/queue/helpers"
|
2
3
|
|
3
4
|
require "socket"
|
4
5
|
require "active_record"
|
@@ -36,6 +37,15 @@ RSpec.configure do |config|
|
|
36
37
|
config.run_all_when_everything_filtered = true
|
37
38
|
config.filter_run :focus
|
38
39
|
|
40
|
+
config.include(Sunspot::Queue::Helpers)
|
41
|
+
config.include(
|
42
|
+
Module.new do
|
43
|
+
def commit
|
44
|
+
without_proxy { Sunspot.commit }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
)
|
48
|
+
|
39
49
|
# Original sunspot session not wrapped in our proxy object
|
40
50
|
session = Sunspot.session
|
41
51
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunspot-queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: resque
|
@@ -43,22 +43,6 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 1.3.0
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: rake
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ! '>='
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
46
|
- !ruby/object:Gem::Dependency
|
63
47
|
name: rspec
|
64
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,6 +182,7 @@ files:
|
|
198
182
|
- lib/sunspot/queue/index_job.rb
|
199
183
|
- lib/sunspot/queue/removal_job.rb
|
200
184
|
- lib/sunspot/queue/session_proxy.rb
|
185
|
+
- lib/sunspot/queue/version.rb
|
201
186
|
- lib/sunspot/queue.rb
|
202
187
|
- lib/sunspot-queue.rb
|
203
188
|
- spec/index_job_spec.rb
|
@@ -219,18 +204,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
219
204
|
- - ! '>='
|
220
205
|
- !ruby/object:Gem::Version
|
221
206
|
version: '0'
|
222
|
-
segments:
|
223
|
-
- 0
|
224
|
-
hash: -3459963560005130599
|
225
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
226
208
|
none: false
|
227
209
|
requirements:
|
228
210
|
- - ! '>='
|
229
211
|
- !ruby/object:Gem::Version
|
230
212
|
version: '0'
|
231
|
-
segments:
|
232
|
-
- 0
|
233
|
-
hash: -3459963560005130599
|
234
213
|
requirements: []
|
235
214
|
rubyforge_project:
|
236
215
|
rubygems_version: 1.8.24
|