sidekiq-activerecord 0.0.5 → 0.0.6
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 +1 -1
- data/lib/sidekiq/active_record/manager_worker.rb +15 -6
- data/lib/sidekiq/active_record/version.rb +1 -1
- data/sidekiq-activerecord.gemspec +1 -1
- data/spec/examples/alias_user_task_worker.rb +4 -0
- data/spec/examples/helper_classes.rb +3 -0
- data/spec/examples/no_alias_user_task_worker.rb +4 -0
- data/spec/sidekiq/active_record/example/alias_user_task_worker_spec.rb +7 -0
- data/spec/sidekiq/active_record/example/no_alias_user_task_worker_spec.rb +7 -0
- data/spec/sidekiq/active_record/manager_worker_spec.rb +36 -6
- data/spec/sidekiq/active_record/task_worker_spec.rb +1 -1
- data/spec/support/database.rb +2 -1
- data/spec/support/factory_girl.rb +2 -1
- data/spec/support/models.rb +4 -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: bd12daf4b1a40526767e3c932dac065426cd76bc
|
4
|
+
data.tar.gz: 1c9131194a47aef814abd6f6888806858d38847d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90f6397634ef7af9778e477bff84528761275a426d404a09787e1cb70a603616cb927f144377e3d83ab00d35be0d5058de85922350dbb77720fe20129b53a0c4
|
7
|
+
data.tar.gz: 4ba64fd648ca8daa7841ba2a84e8be837b66bfed4f556566d130e3c0925a6be0f52bb5abfd1754f6f484d74d27e56488b227c9405639a1e549b7cfcdc9181727
|
data/README.md
CHANGED
@@ -21,7 +21,8 @@ module Sidekiq
|
|
21
21
|
# @param options Hash
|
22
22
|
# :worker_class - the worker class to delegate the task to. Alternative to the default `sidekiq_delegate_task_to`
|
23
23
|
# :identifier_key - the model identifier column. Default 'id'
|
24
|
-
# :
|
24
|
+
# :selected_attributes - the attributes to SELECT for models query
|
25
|
+
# :additional_keys - additional model keys - defaults to :selected_attributes
|
25
26
|
# :batch_size - Specifies the size of each batch to push in bulk.
|
26
27
|
# This is also the number of models to fetch in each find_in_batches query.
|
27
28
|
# Default is 1000.
|
@@ -39,7 +40,8 @@ module Sidekiq
|
|
39
40
|
# sidekiq_delegate_task_to :user_task_worker # or UserTaskWorker
|
40
41
|
# sidekiq_manager_options :batch_size => 500,
|
41
42
|
# :identifier_key => :user_token,
|
42
|
-
# :
|
43
|
+
# :selected_attributes => [:first_name, :last_name, :email],
|
44
|
+
# :additional_keys => [:full_name, :email]
|
43
45
|
# end
|
44
46
|
#
|
45
47
|
# UserSyncer.perform_query_async(User.active, :batch_size => 300)
|
@@ -75,7 +77,8 @@ module Sidekiq
|
|
75
77
|
#
|
76
78
|
# :worker_class - the worker class to delegate the task to. Alternative to `sidekiq_delegate_task_to`
|
77
79
|
# :identifier_key - the model identifier column. Default 'id'
|
78
|
-
# :
|
80
|
+
# :selected_attributes - the attributes to SELECT for models query
|
81
|
+
# :additional_keys - additional model keys - defaults to :selected_attributes
|
79
82
|
# :batch_size - Specifies the size of the batch. Default to 1000.
|
80
83
|
def sidekiq_manager_options(opts = {})
|
81
84
|
@sidekiq_manager_options_hash = get_sidekiq_manager_options.merge((opts || {}))
|
@@ -100,6 +103,7 @@ module Sidekiq
|
|
100
103
|
def default_worker_manager_options
|
101
104
|
{
|
102
105
|
identifier_key: DEFAULT_IDENTIFIER_KEY,
|
106
|
+
selected_attributes: [],
|
103
107
|
additional_keys: [],
|
104
108
|
batch_size: DEFAULT_BATCH_SIZE
|
105
109
|
}
|
@@ -114,8 +118,8 @@ module Sidekiq
|
|
114
118
|
end
|
115
119
|
|
116
120
|
def prepare_models_query(models_query)
|
117
|
-
|
118
|
-
models_query.select(
|
121
|
+
selected_attrs = [models_query.primary_key.to_sym, identifier_key, selected_attributes].uniq
|
122
|
+
models_query.select(selected_attrs)
|
119
123
|
end
|
120
124
|
|
121
125
|
def worker_class
|
@@ -127,8 +131,13 @@ module Sidekiq
|
|
127
131
|
manager_options[:identifier_key]
|
128
132
|
end
|
129
133
|
|
134
|
+
def selected_attributes
|
135
|
+
manager_options[:selected_attributes]
|
136
|
+
end
|
137
|
+
|
130
138
|
def additional_keys
|
131
|
-
manager_options[:additional_keys]
|
139
|
+
additional = manager_options[:additional_keys]
|
140
|
+
additional.present? ? additional : selected_attributes
|
132
141
|
end
|
133
142
|
|
134
143
|
def batch_size
|
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = 'sidekiq-activerecord'
|
8
8
|
spec.version = Sidekiq::ActiveRecord::VERSION
|
9
9
|
spec.authors = ['Adam Farhi']
|
10
|
-
spec.email = ['
|
10
|
+
spec.email = ['yelled3@gmail.com']
|
11
11
|
spec.summary = 'Encapsulates various interactions between Sidekiq and ActiveRecord'
|
12
12
|
spec.description = spec.summary
|
13
13
|
spec.homepage = 'https://github.com/yelled3/sidekiq-activerecord'
|
@@ -1,9 +1,13 @@
|
|
1
|
+
require 'examples/helper_classes'
|
2
|
+
|
1
3
|
module Examples
|
2
4
|
class AliasUserTaskWorker < Sidekiq::ActiveRecord::TaskWorker
|
3
5
|
|
4
6
|
sidekiq_task_model :user # or User class
|
5
7
|
sidekiq_task_options :identifier_key => :email
|
6
8
|
|
9
|
+
sidekiq_options :queue => USER_TASK_QUEUE
|
10
|
+
|
7
11
|
def perform_on_user(new_email = nil)
|
8
12
|
UserMailer.update_email(user, new_email)
|
9
13
|
end
|
@@ -1,9 +1,13 @@
|
|
1
|
+
require 'examples/helper_classes'
|
2
|
+
|
1
3
|
module Examples
|
2
4
|
class NoAliasUserTaskWorker < Sidekiq::ActiveRecord::TaskWorker
|
3
5
|
|
4
6
|
sidekiq_task_model :user # or User class
|
5
7
|
sidekiq_task_options :identifier_key => :email
|
6
8
|
|
9
|
+
sidekiq_options :queue => USER_TASK_QUEUE
|
10
|
+
|
7
11
|
def perform_on_model(new_email = nil)
|
8
12
|
UserMailer.update_email(task_model, new_email)
|
9
13
|
end
|
@@ -17,6 +17,13 @@ module Examples
|
|
17
17
|
allow(logger).to receive(:error)
|
18
18
|
end
|
19
19
|
|
20
|
+
context 'when a sidekiq_options is specified' do
|
21
|
+
it 'sets the queue' do
|
22
|
+
sidekiq_options = task_worker_class.send(:get_sidekiq_options)
|
23
|
+
expect(sidekiq_options['queue']).to eq USER_TASK_QUEUE
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
20
27
|
context 'when the user is not found' do
|
21
28
|
|
22
29
|
let(:unfound_email) { 'unfound@email.com' }
|
@@ -17,6 +17,13 @@ module Examples
|
|
17
17
|
allow(logger).to receive(:error)
|
18
18
|
end
|
19
19
|
|
20
|
+
context 'when a sidekiq_options is specified' do
|
21
|
+
it 'sets the queue' do
|
22
|
+
sidekiq_options = task_worker_class.send(:get_sidekiq_options)
|
23
|
+
expect(sidekiq_options['queue']).to eq USER_TASK_QUEUE
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
20
27
|
context 'when the user is not found' do
|
21
28
|
|
22
29
|
let(:unfound_email) { 'unfound@email.com' }
|
@@ -130,26 +130,57 @@ describe Sidekiq::ActiveRecord::ManagerWorker do
|
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
-
context 'when the
|
133
|
+
context 'when the selected_attributes are specified' do
|
134
134
|
|
135
|
-
let(:
|
135
|
+
let(:selected_attributes) { [:email, :status] }
|
136
136
|
|
137
137
|
def batch_args(*users)
|
138
138
|
{class: worker_class, args: users.map{ |user| [user.id, user.email, user.status] }}
|
139
139
|
end
|
140
140
|
|
141
|
+
context 'as method arguments' do
|
142
|
+
it 'pushes a bulk of all user ids and selected_attributes' do
|
143
|
+
expect(sidekiq_client).to receive(:push_bulk).with( batch_args(user_1, user_2, user_3) )
|
144
|
+
run_worker({selected_attributes: selected_attributes})
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'as sidekiq_manager_options' do
|
149
|
+
around do |example|
|
150
|
+
mock_options(:selected_attributes => selected_attributes)
|
151
|
+
example.run
|
152
|
+
mock_options(:selected_attributes => [])
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'pushes a bulk of all user ids and selected_attributes' do
|
156
|
+
expect(sidekiq_client).to receive(:push_bulk).with( batch_args(user_1, user_2, user_3) )
|
157
|
+
run_worker
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'when the additional_keys are specified' do
|
164
|
+
|
165
|
+
let(:selected_attributes) { [:first_name, :last_name] }
|
166
|
+
let(:additional_keys) { [:full_name] } # a method on User model
|
167
|
+
|
168
|
+
def batch_args(*users)
|
169
|
+
{class: worker_class, args: users.map{ |user| [user.id, user.full_name] }}
|
170
|
+
end
|
171
|
+
|
141
172
|
context 'as method arguments' do
|
142
173
|
it 'pushes a bulk of all user ids and additional_keys' do
|
143
174
|
expect(sidekiq_client).to receive(:push_bulk).with( batch_args(user_1, user_2, user_3) )
|
144
|
-
run_worker(
|
175
|
+
run_worker(selected_attributes: selected_attributes, additional_keys: additional_keys)
|
145
176
|
end
|
146
177
|
end
|
147
178
|
|
148
179
|
context 'as sidekiq_manager_options' do
|
149
180
|
around do |example|
|
150
|
-
mock_options(:additional_keys => additional_keys)
|
181
|
+
mock_options(:selected_attributes => selected_attributes, :additional_keys => additional_keys)
|
151
182
|
example.run
|
152
|
-
mock_options(:additional_keys => [])
|
183
|
+
mock_options(:selected_attributes => [], :additional_keys => [])
|
153
184
|
end
|
154
185
|
|
155
186
|
it 'pushes a bulk of all user ids and additional_keys' do
|
@@ -157,7 +188,6 @@ describe Sidekiq::ActiveRecord::ManagerWorker do
|
|
157
188
|
run_worker
|
158
189
|
end
|
159
190
|
end
|
160
|
-
|
161
191
|
end
|
162
192
|
|
163
193
|
context 'when the identifier_key is specified' do
|
@@ -223,7 +223,7 @@ describe Sidekiq::ActiveRecord::TaskWorker do
|
|
223
223
|
context "when the specified model doesn't match the task_model class" do
|
224
224
|
|
225
225
|
let(:unrelated_model) {
|
226
|
-
Struct.new(:id, :
|
226
|
+
Struct.new(:id, :first_name).new(55, 'Mike')
|
227
227
|
}
|
228
228
|
|
229
229
|
it "raises an ArgumentError and doesn't call perform_async" do
|
data/spec/support/database.rb
CHANGED
data/spec/support/models.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Farhi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -96,7 +96,7 @@ dependencies:
|
|
96
96
|
version: '4.0'
|
97
97
|
description: Encapsulates various interactions between Sidekiq and ActiveRecord
|
98
98
|
email:
|
99
|
-
-
|
99
|
+
- yelled3@gmail.com
|
100
100
|
executables: []
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|