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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9139afdf7efd7b2b766b0f0c79cbffe98cf0a3df
4
- data.tar.gz: 579edad53f837e6254d84205f0a0c58985f95fb0
3
+ metadata.gz: bd12daf4b1a40526767e3c932dac065426cd76bc
4
+ data.tar.gz: 1c9131194a47aef814abd6f6888806858d38847d
5
5
  SHA512:
6
- metadata.gz: 3dd406e37261203cb64935227bef8bc3448917a7aef5f1035f0a4baea91fe41fbb38b4483155a37eebc732c5504c44ba98b4a94add2b15b9fb068fce1917cbc9
7
- data.tar.gz: f6ddc5772b85d0f80dbb9931fb1087dc8403480eb1bfd0b17df11002bed8ffd06006198cb54ef29fcabec8b93fe4a4bb8370669262df788751add0fa0c5442d3
6
+ metadata.gz: 90f6397634ef7af9778e477bff84528761275a426d404a09787e1cb70a603616cb927f144377e3d83ab00d35be0d5058de85922350dbb77720fe20129b53a0c4
7
+ data.tar.gz: 4ba64fd648ca8daa7841ba2a84e8be837b66bfed4f556566d130e3c0925a6be0f52bb5abfd1754f6f484d74d27e56488b227c9405639a1e549b7cfcdc9181727
data/README.md CHANGED
@@ -60,7 +60,7 @@ Checkout the project's [Wiki Page](https://github.com/sidekiq-orm/sidekiq-active
60
60
 
61
61
  Add this line to your application's Gemfile:
62
62
 
63
- gem 'sidekiq-activerecord', '~> 0.0.4'
63
+ gem 'sidekiq-activerecord', '~> 0.0.5'
64
64
 
65
65
  And then execute:
66
66
 
@@ -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
- # :additional_keys - additional model keys
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
- # :additional_keys => [:status]
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
- # :additional_keys - additional model keys
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
- selected_attributes = [models_query.primary_key.to_sym, identifier_key, additional_keys].uniq
118
- models_query.select(selected_attributes)
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
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module ActiveRecord
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
@@ -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 = ['afarhi@ebay.com']
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,4 +1,7 @@
1
1
  module Examples
2
+
3
+ USER_TASK_QUEUE = :user_task_queue
4
+
2
5
  class UserMailer
3
6
  def self.update_email(user, new_email)
4
7
  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 additional_keys are specified' do
133
+ context 'when the selected_attributes are specified' do
134
134
 
135
- let(:additional_keys) { [:email, :status] }
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({additional_keys: additional_keys})
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, :name).new(55, 'Mike')
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
@@ -3,7 +3,8 @@ ActiveRecord::Base.establish_connection(db_config)
3
3
  connection = ActiveRecord::Base.connection
4
4
 
5
5
  connection.create_table :users, force: true do |t|
6
- t.string :name
6
+ t.string :first_name
7
+ t.string :last_name
7
8
  t.string :email
8
9
  t.string :status
9
10
  t.timestamps
@@ -5,7 +5,8 @@ end
5
5
  FactoryGirl.define do
6
6
  factory :user do
7
7
 
8
- sequence(:name) { |n| "name-#{n}" }
8
+ sequence(:first_name) { |n| "first-name-#{n}" }
9
+ sequence(:last_name) { |n| "last-name-#{n}" }
9
10
  sequence(:email) { |n| "email-#{n}" }
10
11
 
11
12
  trait :active do
@@ -5,4 +5,8 @@ class User < ActiveRecord::Base
5
5
  def active?
6
6
  status.try(:to_sym) == :active
7
7
  end
8
+
9
+ def full_name
10
+ "#{first_name} #{last_name}"
11
+ end
8
12
  end
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.5
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-21 00:00:00.000000000 Z
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
- - afarhi@ebay.com
99
+ - yelled3@gmail.com
100
100
  executables: []
101
101
  extensions: []
102
102
  extra_rdoc_files: []