tire_async_index 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +10 -0
- data/lib/tire/model/async_callbacks.rb +33 -0
- data/lib/tire_async_index/configuration.rb +26 -0
- data/lib/tire_async_index/exceptions.rb +3 -0
- data/lib/tire_async_index/version.rb +3 -0
- data/lib/tire_async_index/workers/resque_update_index_job.rb +9 -0
- data/lib/tire_async_index/workers/sidekiq_update_index_worker.rb +10 -0
- data/lib/tire_async_index.rb +27 -0
- data/spec/test_helper.rb +18 -0
- data/spec/test_schema.rb +7 -0
- data/spec/tire_async_index_spec.rb +86 -0
- data/tire_async_index.gemspec +29 -0
- metadata +176 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 787c2bf5248a7a3ac44a08e3ca0861bdd255dd04
|
4
|
+
data.tar.gz: 27c1075ca9d55f3c24fa08721b8d251895f9a14c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 577d09324ee37b127f7baa01e69282a0f6c173f328955ed68d8a2afb2190235e4d24cb599854263c1d33c959f286adf7611f7e0cf7c832439cf61436f8603d3d
|
7
|
+
data.tar.gz: 64603ddf1d0422eb8a092df54736c63c401a8a3d8d2f21afe8cf167d17db9718e45e1a646d78cb79fde0bb0e2bf6acce20099d8ed3a09a084f5d3097ea6ac3af
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Sergey Efremov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# TireAsyncIndex
|
2
|
+
|
3
|
+
It's extension for [Tire](https://github.com/karmi/tire/) (client for the Elasticsearch search engine), which allow to update index of ActiveRecord model using background job (based on [Sidekiq](https://github.com/mperham/sidekiq) or [Resque](https://github.com/resque/resque)).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'tire_async_index'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install tire_async_index
|
18
|
+
|
19
|
+
## Configuration
|
20
|
+
|
21
|
+
You could configure TireAsyncIndex in initializer:
|
22
|
+
|
23
|
+
TireAsyncIndex.configure do |config|
|
24
|
+
config.background_engine :sidekiq # or :resque
|
25
|
+
config.use_queue :high # name of your queue
|
26
|
+
end
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Just add AsyncCallbacks to your model:
|
31
|
+
|
32
|
+
class User < ActiveRecord::Base
|
33
|
+
include Tire::Model::Search
|
34
|
+
include Tire::Model::AsyncCallbacks
|
35
|
+
|
36
|
+
...
|
37
|
+
end
|
38
|
+
|
39
|
+
That's all.
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Tire
|
2
|
+
module Model
|
3
|
+
module AsyncCallbacks
|
4
|
+
def self.included(base)
|
5
|
+
if base.respond_to?(:after_save) && base.respond_to?(:after_destroy)
|
6
|
+
puts "asdfadasdas"
|
7
|
+
base.send :after_save, lambda {
|
8
|
+
case TireAsyncIndex.engine
|
9
|
+
when :sidekiq
|
10
|
+
SidekiqUpdateIndexWorker.perform_async(base.name, id)
|
11
|
+
when :resque
|
12
|
+
Resque.enqueue(ResqueUpdateIndexJob, base.name, id)
|
13
|
+
else
|
14
|
+
tire.update_index
|
15
|
+
end
|
16
|
+
self
|
17
|
+
}
|
18
|
+
base.send :after_destroy, lambda { tire.update_index }, :order => :first
|
19
|
+
end
|
20
|
+
|
21
|
+
if base.respond_to?(:before_destroy) && !base.instance_methods.map(&:to_sym).include?(:destroyed?)
|
22
|
+
base.class_eval do
|
23
|
+
before_destroy { @destroyed = true }
|
24
|
+
def destroyed?; !!@destroyed; end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module TireAsyncIndex
|
2
|
+
class Configuration
|
3
|
+
AVALAIBLE_ENGINE = [:sidekiq, :resque, :none]
|
4
|
+
|
5
|
+
attr_accessor :queue
|
6
|
+
attr_accessor :engine
|
7
|
+
|
8
|
+
def background_engine type
|
9
|
+
if AVALAIBLE_ENGINE.include?(type.to_sym)
|
10
|
+
@engine = type.to_sym
|
11
|
+
else
|
12
|
+
raise EngineNotFound, "Background Engine '#{type}' not found"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def use_queue name
|
17
|
+
@queue = name.to_sym
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@queue = :normal
|
22
|
+
@engine = :none
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "tire_async_index/configuration"
|
2
|
+
require "tire_async_index/exceptions"
|
3
|
+
require "tire_async_index/version"
|
4
|
+
|
5
|
+
module TireAsyncIndex
|
6
|
+
extend self
|
7
|
+
attr_accessor :configuration
|
8
|
+
|
9
|
+
def configure
|
10
|
+
self.configuration ||= Configuration.new
|
11
|
+
yield(configuration)
|
12
|
+
end
|
13
|
+
|
14
|
+
def queue_name
|
15
|
+
self.configuration.queue
|
16
|
+
end
|
17
|
+
|
18
|
+
def engine
|
19
|
+
self.configuration.engine
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
TireAsyncIndex.configure {}
|
24
|
+
|
25
|
+
require 'tire_async_index/workers/sidekiq_update_index_worker' if defined?(Sidekiq)
|
26
|
+
require 'tire_async_index/workers/resque_update_index_job' if defined?(Resque)
|
27
|
+
require 'tire/model/async_callbacks'
|
data/spec/test_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
require "tire"
|
4
|
+
require 'rails'
|
5
|
+
require 'active_record'
|
6
|
+
require 'nulldb_rspec'
|
7
|
+
require 'nulldb/rails'
|
8
|
+
#include NullDB::RSpec::NullifiedDatabase
|
9
|
+
NullDB.configure {|ndb| ndb.project_root = 'spec'}
|
10
|
+
ActiveRecord::Base.establish_connection :adapter => :nulldb,
|
11
|
+
:schema => 'test_schema.rb'
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.mock_with :rspec
|
15
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
16
|
+
config.filter_run :focus => true
|
17
|
+
config.run_all_when_everything_filtered = true
|
18
|
+
end
|
data/spec/test_schema.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'tire'
|
3
|
+
require 'sidekiq'
|
4
|
+
require 'resque'
|
5
|
+
require 'tire_async_index'
|
6
|
+
|
7
|
+
class User < ActiveRecord::Base
|
8
|
+
include Tire::Model::AsyncCallbacks
|
9
|
+
end
|
10
|
+
|
11
|
+
describe TireAsyncIndex do
|
12
|
+
context "configurable" do
|
13
|
+
it "valid default config settings" do
|
14
|
+
TireAsyncIndex.queue_name.should eql :normal
|
15
|
+
TireAsyncIndex.engine.should eql :none
|
16
|
+
end
|
17
|
+
|
18
|
+
it "set queue name" do
|
19
|
+
TireAsyncIndex.configure do |config|
|
20
|
+
config.use_queue :high
|
21
|
+
end
|
22
|
+
|
23
|
+
TireAsyncIndex.queue_name.should eql :high
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be able to set sidekiq as engine" do
|
27
|
+
TireAsyncIndex.configure do |config|
|
28
|
+
config.background_engine :sidekiq
|
29
|
+
end
|
30
|
+
|
31
|
+
TireAsyncIndex.engine.should eql :sidekiq
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be able to set resque as engine" do
|
35
|
+
TireAsyncIndex.configure do |config|
|
36
|
+
config.background_engine :resque
|
37
|
+
end
|
38
|
+
|
39
|
+
TireAsyncIndex.engine.should eql :resque
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should not be able to set not supported engine" do
|
43
|
+
expect {
|
44
|
+
TireAsyncIndex.configure do |config|
|
45
|
+
config.background_engine :some_engine
|
46
|
+
end
|
47
|
+
}.to raise_error(TireAsyncIndex::EngineNotFound)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "integration" do
|
52
|
+
|
53
|
+
it "should not start backroub on no engine" do
|
54
|
+
TireAsyncIndex.configure do |config|
|
55
|
+
config.background_engine :none
|
56
|
+
end
|
57
|
+
a = User.new
|
58
|
+
a.stub(:tire) { a }
|
59
|
+
a.should_receive(:update_index)
|
60
|
+
a.save
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should start sidekiq" do
|
64
|
+
TireAsyncIndex.configure do |config|
|
65
|
+
config.background_engine :sidekiq
|
66
|
+
end
|
67
|
+
|
68
|
+
SidekiqUpdateIndexWorker.should_receive(:perform_async).with("User", instance_of(Fixnum))
|
69
|
+
|
70
|
+
a = User.new
|
71
|
+
a.save
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should start resque" do
|
75
|
+
TireAsyncIndex.configure do |config|
|
76
|
+
config.background_engine :resque
|
77
|
+
end
|
78
|
+
|
79
|
+
Resque.should_receive(:enqueue).with(ResqueUpdateIndexJob, "User", instance_of(Fixnum))
|
80
|
+
|
81
|
+
a = User.new
|
82
|
+
a.save
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tire_async_index/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tire_async_index"
|
8
|
+
spec.version = TireAsyncIndex::VERSION
|
9
|
+
spec.authors = ["Sergey Efremov"]
|
10
|
+
spec.email = ["efremov.sergey@gmail.com"]
|
11
|
+
spec.description = "Update tire (elasticsearch) index async with Sidekiq or Resque"
|
12
|
+
spec.summary = "Update tire (elasticsearch) index async with Sidekiq or Resque"
|
13
|
+
spec.homepage = "http://github.com/EvilFaeton/tire_async_index"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "tire"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rails", "~> 3.2"
|
25
|
+
spec.add_development_dependency "activerecord-nulldb-adapter"
|
26
|
+
spec.add_development_dependency "sidekiq"
|
27
|
+
spec.add_development_dependency "resque"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tire_async_index
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Efremov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-03-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tire
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activerecord-nulldb-adapter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sidekiq
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: resque
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Update tire (elasticsearch) index async with Sidekiq or Resque
|
126
|
+
email:
|
127
|
+
- efremov.sergey@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- .gitignore
|
133
|
+
- .rspec
|
134
|
+
- Gemfile
|
135
|
+
- LICENSE.txt
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- lib/tire/model/async_callbacks.rb
|
139
|
+
- lib/tire_async_index.rb
|
140
|
+
- lib/tire_async_index/configuration.rb
|
141
|
+
- lib/tire_async_index/exceptions.rb
|
142
|
+
- lib/tire_async_index/version.rb
|
143
|
+
- lib/tire_async_index/workers/resque_update_index_job.rb
|
144
|
+
- lib/tire_async_index/workers/sidekiq_update_index_worker.rb
|
145
|
+
- spec/test_helper.rb
|
146
|
+
- spec/test_schema.rb
|
147
|
+
- spec/tire_async_index_spec.rb
|
148
|
+
- tire_async_index.gemspec
|
149
|
+
homepage: http://github.com/EvilFaeton/tire_async_index
|
150
|
+
licenses:
|
151
|
+
- MIT
|
152
|
+
metadata: {}
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - '>='
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
requirements: []
|
168
|
+
rubyforge_project:
|
169
|
+
rubygems_version: 2.0.1
|
170
|
+
signing_key:
|
171
|
+
specification_version: 4
|
172
|
+
summary: Update tire (elasticsearch) index async with Sidekiq or Resque
|
173
|
+
test_files:
|
174
|
+
- spec/test_helper.rb
|
175
|
+
- spec/test_schema.rb
|
176
|
+
- spec/tire_async_index_spec.rb
|