chewy_kiqqer 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +4 -1
- data/lib/chewy_kiqqer/mixin.rb +15 -5
- data/lib/chewy_kiqqer/version.rb +1 -1
- data/spec/mixin_spec.rb +17 -6
- data/spec/{workder.spec.rb → worker.spec.rb} +0 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b46e354039335e662d5a2703dfefede25e6eb3ae
|
4
|
+
data.tar.gz: c274a92f28b5123db90522739df092eb0bdf0488
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 093e22e868d55e03a0a508b48aee199ee5887664a5ae09ca9decb533ad7c8ba2f7ebf0c90a03d5383cd29b7969950e8f2e22ae16aaea924d3e31a7006f8aef1a
|
7
|
+
data.tar.gz: 60a94f08eca01d4b087cdcb48da86949ade028aeaf4aa6479d79763b5a21156aef966ebc8ed3f12bba8a4784095f5c36e283fd12cd2f17c4ee13a6356135cb0c
|
data/README.md
CHANGED
@@ -25,10 +25,13 @@ Just add the module and set it up:
|
|
25
25
|
class User < ActiveRecord::Base
|
26
26
|
include ChewyKiqqer::Mixin
|
27
27
|
|
28
|
-
async_update_index 'users#user'
|
28
|
+
async_update_index index: 'users#user', queue: :other_than_default
|
29
29
|
end
|
30
30
|
|
31
31
|
You can also include the mixin into ActiveRecord::Base in an initializer if it should be generally available.
|
32
|
+
The queue name is optional. You can also set a default queue name for your application with:
|
33
|
+
|
34
|
+
ChewyKiqqer.default_queue = :my_queue
|
32
35
|
|
33
36
|
## Contributing
|
34
37
|
|
data/lib/chewy_kiqqer/mixin.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
require 'active_support/concern'
|
2
2
|
|
3
3
|
module ChewyKiqqer
|
4
|
+
|
5
|
+
def self.default_queue=(queue)
|
6
|
+
@default_queue = queue
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.default_queue
|
10
|
+
@default_queue || 'default'
|
11
|
+
end
|
12
|
+
|
4
13
|
module Mixin
|
5
14
|
|
6
15
|
extend ActiveSupport::Concern
|
@@ -9,15 +18,16 @@ module ChewyKiqqer
|
|
9
18
|
|
10
19
|
attr_reader :index_name
|
11
20
|
|
12
|
-
def async_update_index(
|
13
|
-
@index_name =
|
14
|
-
after_save :
|
15
|
-
after_destroy :
|
21
|
+
def async_update_index(index: nil, queue: ChewyKiqqer::default_queue)
|
22
|
+
@index_name = index
|
23
|
+
after_save :queue_chewy_job
|
24
|
+
after_destroy :queue_chewy_job
|
25
|
+
ChewyKiqqer::Worker.sidekiq_options queue: queue
|
16
26
|
end
|
17
27
|
|
18
28
|
end
|
19
29
|
|
20
|
-
def
|
30
|
+
def queue_chewy_job
|
21
31
|
ChewyKiqqer::Worker.perform_async(self.class.index_name, id)
|
22
32
|
end
|
23
33
|
end
|
data/lib/chewy_kiqqer/version.rb
CHANGED
data/spec/mixin_spec.rb
CHANGED
@@ -13,15 +13,26 @@ describe ChewyKiqqer::Mixin do
|
|
13
13
|
|
14
14
|
context 'class methods' do
|
15
15
|
it 'installs the hooks' do
|
16
|
-
Gummi.should_receive(:after_save).with(:
|
17
|
-
Gummi.should_receive(:after_destroy).with(:
|
18
|
-
Gummi.async_update_index('xxx')
|
16
|
+
Gummi.should_receive(:after_save).with(:queue_chewy_job)
|
17
|
+
Gummi.should_receive(:after_destroy).with(:queue_chewy_job)
|
18
|
+
Gummi.async_update_index(index: 'xxx')
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'knows the index_name' do
|
22
|
-
Gummi.async_update_index('bar#foo')
|
22
|
+
Gummi.async_update_index(index: 'bar#foo')
|
23
23
|
Gummi.index_name.should eq 'bar#foo'
|
24
24
|
end
|
25
|
+
|
26
|
+
it 'sets the queue name' do
|
27
|
+
ChewyKiqqer::Worker.should_receive(:sidekiq_options).with(queue: :some_queue)
|
28
|
+
Gummi.async_update_index(index: 'xxx', queue: :some_queue)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'uses the default queue if none was specified' do
|
32
|
+
ChewyKiqqer::Worker.should_receive(:sidekiq_options).with(queue: :default3)
|
33
|
+
ChewyKiqqer.default_queue = :default3
|
34
|
+
Gummi.async_update_index(index: 'xxx')
|
35
|
+
end
|
25
36
|
end
|
26
37
|
|
27
38
|
context '#queue_job' do
|
@@ -29,9 +40,9 @@ describe ChewyKiqqer::Mixin do
|
|
29
40
|
let(:record) { Gummi.new }
|
30
41
|
|
31
42
|
it 'queues the job' do
|
32
|
-
Gummi.async_update_index 'foo#bar'
|
43
|
+
Gummi.async_update_index index: 'foo#bar'
|
33
44
|
ChewyKiqqer::Worker.should_receive(:perform_async).with('foo#bar', 17)
|
34
|
-
record.
|
45
|
+
record.queue_chewy_job
|
35
46
|
end
|
36
47
|
|
37
48
|
end
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chewy_kiqqer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Hahn
|
@@ -112,7 +112,7 @@ files:
|
|
112
112
|
- lib/chewy_kiqqer/version.rb
|
113
113
|
- lib/chewy_kiqqer/worker.rb
|
114
114
|
- spec/mixin_spec.rb
|
115
|
-
- spec/
|
115
|
+
- spec/worker.spec.rb
|
116
116
|
homepage: ''
|
117
117
|
licenses:
|
118
118
|
- Apache V2
|
@@ -140,4 +140,4 @@ summary: Small helper gem that allows you to automatically run all chewy index u
|
|
140
140
|
in sidekiq
|
141
141
|
test_files:
|
142
142
|
- spec/mixin_spec.rb
|
143
|
-
- spec/
|
143
|
+
- spec/worker.spec.rb
|