activesearch 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile +1 -1
- data/activesearch.gemspec +1 -0
- data/lib/activesearch/algolia.rb +4 -10
- data/lib/activesearch/algolia/worker.rb +18 -0
- data/lib/activesearch/version.rb +1 -1
- data/spec/algolia_spec.rb +6 -3
- data/spec/spec_helper.rb +2 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWZiODUwMjI1M2M2OTQwZTBjOWI4ZWIzZTRiODFhYmEyMzg5MjAwNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NmRmNTIwNjA1M2Y4NTJhZGQ2NzYyMTAwOTdlZmQyM2YyYzA4YmRkOA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2M1ZGNmMTVjYjA1YmM1YTUxNDk5ZWIxNzI0MTZjOWE4ZjE5ZTJmZmEwOWYx
|
10
|
+
OTNkZDFlZDM2NDA0NWYzMGE5ZjYxMGI3OGNmMzExMGE5YTkwNmM5Y2JjNWFh
|
11
|
+
OTY5ZDZiNzA2YWYzYWQ2M2I3MDc5NTBiZmVlZjY1MzY5NGIyNzI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzdhYjBmNDNkYzFhMjdmNDhlMzczOWViOWEzMzFjMTAyMDVhNjY2MjMzMjI0
|
14
|
+
ZDA2MmY0YmNjY2E5MzEzYzZlNWQxMDc4OWNiMjc0OGQ3N2RlNDYxMWFkNDQy
|
15
|
+
Yzg3Yjg4NzQzMjBlOTgzOTE0ZjQ5ZmUyYjFiM2E5Zjg2MWUxOWI=
|
data/Gemfile
CHANGED
data/activesearch.gemspec
CHANGED
data/lib/activesearch/algolia.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "activesearch/algolia/client"
|
2
|
+
require "activesearch/algolia/worker"
|
2
3
|
require "activesearch/base"
|
3
4
|
require "activesearch/proxy"
|
4
5
|
|
@@ -26,7 +27,7 @@ module ActiveSearch
|
|
26
27
|
conditions.map { |c| c.join(':') }.join(',')
|
27
28
|
end
|
28
29
|
|
29
|
-
module Algolia
|
30
|
+
module Algolia
|
30
31
|
def self.included(base)
|
31
32
|
base.class_eval do
|
32
33
|
include Base
|
@@ -35,14 +36,11 @@ module ActiveSearch
|
|
35
36
|
|
36
37
|
protected
|
37
38
|
def reindex
|
38
|
-
|
39
|
-
rescue
|
40
|
-
self.touch
|
41
|
-
false
|
39
|
+
Worker.new.async.perform(task: :reindex, id: indexable_id, doc: self.to_indexable)
|
42
40
|
end
|
43
41
|
|
44
42
|
def deindex
|
45
|
-
|
43
|
+
Worker.new.async.perform(task: :deindex, id: indexable_id)
|
46
44
|
end
|
47
45
|
|
48
46
|
def to_indexable
|
@@ -57,9 +55,5 @@ module ActiveSearch
|
|
57
55
|
end
|
58
56
|
doc
|
59
57
|
end
|
60
|
-
|
61
|
-
def algolia_client
|
62
|
-
@algolia_client ||= Client.new
|
63
|
-
end
|
64
58
|
end
|
65
59
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "sucker_punch"
|
2
|
+
|
3
|
+
class ActiveSearch::Algolia::Worker
|
4
|
+
include SuckerPunch::Job
|
5
|
+
|
6
|
+
def perform(msg)
|
7
|
+
begin
|
8
|
+
case msg[:task]
|
9
|
+
when :reindex
|
10
|
+
::ActiveSearch::Algolia::Client.new.save(msg[:id], msg[:doc])
|
11
|
+
when :deindex
|
12
|
+
::ActiveSearch::Algolia::Client.new.delete(msg[:id])
|
13
|
+
end
|
14
|
+
rescue Exception => e
|
15
|
+
perform(msg.merge!(retries: msg[:retries].to_i + 1)) unless msg[:retries].to_i >= 3
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/activesearch/version.rb
CHANGED
data/spec/algolia_spec.rb
CHANGED
@@ -12,11 +12,14 @@ describe ActiveSearch::Algolia do
|
|
12
12
|
ActiveSearch::Algolia::Client.new.delete_index
|
13
13
|
end
|
14
14
|
|
15
|
-
context "
|
15
|
+
context "retry on errors" do
|
16
16
|
before do
|
17
|
+
times_called = 0
|
17
18
|
@instance = AlgoliaModel.new(title: "Example")
|
18
|
-
|
19
|
-
|
19
|
+
ActiveSearch::Algolia::Client.should_receive(:put).exactly(3).times.and_return do
|
20
|
+
times_called += 1
|
21
|
+
raise Errno::ECONNRESET if times_called <= 2
|
22
|
+
end
|
20
23
|
end
|
21
24
|
|
22
25
|
subject { -> { @instance.save } }
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activesearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Alvarez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sucker_punch
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,6 +168,7 @@ files:
|
|
154
168
|
- lib/activesearch.rb
|
155
169
|
- lib/activesearch/algolia.rb
|
156
170
|
- lib/activesearch/algolia/client.rb
|
171
|
+
- lib/activesearch/algolia/worker.rb
|
157
172
|
- lib/activesearch/base.rb
|
158
173
|
- lib/activesearch/elastic_search.rb
|
159
174
|
- lib/activesearch/mongoid.rb
|