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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDUxNjIzNjY2NmQxYjIzYmQ4NzA0NjRmYThjNThmY2ZhNjk4N2VlNw==
4
+ NWZiODUwMjI1M2M2OTQwZTBjOWI4ZWIzZTRiODFhYmEyMzg5MjAwNw==
5
5
  data.tar.gz: !binary |-
6
- ZjZmZDhkODU0NzI4MDU0ZjU5YWUzODcyMGFlZDhlNGMyNDk1NjRhMw==
6
+ NmRmNTIwNjA1M2Y4NTJhZGQ2NzYyMTAwOTdlZmQyM2YyYzA4YmRkOA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MTA2OTEwMzMxYWE2ZTI4MTg3MzcyNTE2MmE4ZGU1ZDc4YjZjMmU2MjBjOTJm
10
- ODc2MTNiNmUzZjhkM2E2ZTNlOGQ0OGYzOWJhYTdiNTUxMTYzNzA1N2JmZjcz
11
- YTc3YTM5Nzc1OWYxYzU1YzZmZGUyYTliZmE1NDllY2YxNDYzZGY=
9
+ M2M1ZGNmMTVjYjA1YmM1YTUxNDk5ZWIxNzI0MTZjOWE4ZjE5ZTJmZmEwOWYx
10
+ OTNkZDFlZDM2NDA0NWYzMGE5ZjYxMGI3OGNmMzExMGE5YTkwNmM5Y2JjNWFh
11
+ OTY5ZDZiNzA2YWYzYWQ2M2I3MDc5NTBiZmVlZjY1MzY5NGIyNzI=
12
12
  data.tar.gz: !binary |-
13
- MzM2NGFkNWZhZmZmMjY1MDNmZjJmMzI4MzBhNTI0OGJlMWRhOTg0YmJlNDRh
14
- MjI3OWFiYzIxYjU2NTM4OWRlMTFlZGFmYjkyNzYwYzAzMjdkM2FhN2U5Zjg4
15
- NjFlYTBmZTFjNjJkMDRiYTA4MDFjYTkxOTI3YWQzZWVmZjQ5MjU=
13
+ NzdhYjBmNDNkYzFhMjdmNDhlMzczOWViOWEzMzFjMTAyMDVhNjY2MjMzMjI0
14
+ ZDA2MmY0YmNjY2E5MzEzYzZlNWQxMDc4OWNiMjc0OGQ3N2RlNDYxMWFkNDQy
15
+ Yzg3Yjg4NzQzMjBlOTgzOTE0ZjQ5ZmUyYjFiM2E5Zjg2MWUxOWI=
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in activesearch.gemspec
4
- gemspec
4
+ gemspec
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_dependency "activesupport"
21
+ gem.add_dependency "sucker_punch"
21
22
 
22
23
  gem.add_development_dependency "rspec"
23
24
  gem.add_development_dependency "rspec-mocks"
@@ -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
- algolia_client.save(indexable_id, self.to_indexable)
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
- algolia_client.delete(indexable_id)
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
@@ -1,3 +1,3 @@
1
1
  module ActiveSearch
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -12,11 +12,14 @@ describe ActiveSearch::Algolia do
12
12
  ActiveSearch::Algolia::Client.new.delete_index
13
13
  end
14
14
 
15
- context "errors on save" do
15
+ context "retry on errors" do
16
16
  before do
17
+ times_called = 0
17
18
  @instance = AlgoliaModel.new(title: "Example")
18
- @instance.should_receive(:touch).once
19
- ActiveSearch::Algolia::Client.any_instance.stub(:save).and_raise(Errno::ECONNRESET)
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 } }
@@ -1,5 +1,7 @@
1
1
  require 'active_model'
2
2
  require 'active_attr'
3
+ require 'sucker_punch'
4
+ require 'sucker_punch/testing/inline'
3
5
 
4
6
  class ActiveMimic
5
7
  extend ActiveModel::Callbacks
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.2
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-10 00:00:00.000000000 Z
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