sucker_punch 0.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,3 +1,9 @@
1
+ 0.4.1
2
+ --------
3
+
4
+ - Remove `size` option when defining a queue, prefer `workers`
5
+ - Update Celluloid dependency
6
+
1
7
  0.4
2
8
  -----------
3
9
  - Prefer `workers` stat method over `size`
data/README.md CHANGED
@@ -110,21 +110,21 @@ SuckerPunch::Queue[:log_queue].busy_size # => 4
110
110
  SuckerPunch::Queue[:log_queue].idle_size # => 3
111
111
  ```
112
112
 
113
- ## Testing
113
+ ## Testing (Only 0.3.1+)
114
114
 
115
115
  ```Ruby
116
116
  # spec/spec_helper.rb
117
117
  require 'sucker_punch/testing'
118
118
  ```
119
119
 
120
- Requiring this library completely stubs out the internals of Sucker Puncker, but will provide the necessary tools to confirm your jobs are being enqueucompletely stubs out the internals of Sucker Puncker, but will provide the necessary tools to confirm your jobs are being enqueued.
120
+ Requiring this library completely stubs out the internals of Sucker Punch, but will provide the necessary tools to confirm your jobs are being enqueud.
121
121
 
122
122
  ```Ruby
123
123
  # spec/spec_helper.rb
124
124
  require 'sucker_punch/testing'
125
125
 
126
126
  RSpec.configure do |config|
127
- config.after(:before) do
127
+ config.after do
128
128
  SuckerPunch.reset! # => Resets the queues and jobs in the queues before each test
129
129
  end
130
130
  end
@@ -134,7 +134,7 @@ SuckerPunch.config do
134
134
  queue name: :email, worker: EmailWorker, workers: 2
135
135
  end
136
136
 
137
- # config/workers/email_worker.rb
137
+ # app/workers/email_worker.rb
138
138
  class EmailWorker
139
139
  include SuckerPunch::Worker
140
140
 
@@ -151,9 +151,6 @@ class User < ActiveRecord::Base
151
151
  end
152
152
  end
153
153
 
154
- # spec/spec_helper.rb
155
- require 'sucker_punch/testing'
156
-
157
154
  # spec/models/user_spec.rb
158
155
  require 'spec_helper'
159
156
 
@@ -180,6 +177,45 @@ SuckerPunch::Queue[:log_queue].async.perform("login")
180
177
 
181
178
  ## Troubleshooting
182
179
 
180
+ If you're running tests in transactions (using DatabaseCleaner or a native solution), Sucker Punch workers may have trouble finding database records that were created during test setup because the worker class is running in a separate thread and the Transaction operates on a different thread so it clears out the data before the worker can do its business. The best thing to do is cleanup data created for tests workers through a truncation strategy by tagging the rspec tests as workers and then specifying the strategy in `spec_helper` like below:
181
+
182
+ ```Ruby
183
+ # spec/spec_helper.rb
184
+ RSpec.configure do |config|
185
+ config.before(:each) do
186
+ DatabaseCleaner.strategy = :transaction
187
+ end
188
+
189
+ # Clean up all worker specs with truncation
190
+ config.before(:each, :worker => true) do
191
+ DatabaseCleaner.strategy = :truncation
192
+ end
193
+
194
+ config.before(:each) do
195
+ DatabaseCleaner.start
196
+ end
197
+
198
+ config.after(:each) do
199
+ DatabaseCleaner.clean
200
+ end
201
+
202
+ # spec/workers/email_worker_spec.rb
203
+ require 'spec_helper'
204
+
205
+ # Tag the spec as a worker spec so data is persisted long enough for the test
206
+ describe EmailWorker, worker: true do
207
+ describe "#perform" do
208
+ let(:user) { FactoryGirl.create(:user) }
209
+
210
+ it "delivers an email" do
211
+ expect {
212
+ EmailWorker.new.perform(user.id)
213
+ }.to change{ ActionMailer::Base.deliveries.size }.by(1)
214
+ end
215
+ end
216
+ end
217
+ ```
218
+
183
219
  When using Passenger or Unicorn, you should configure the queues within a block that runs after the child process is forked.
184
220
 
185
221
  ```Ruby
data/lib/sucker_punch.rb CHANGED
@@ -18,7 +18,6 @@ module SuckerPunch
18
18
  klass = options.fetch(:worker)
19
19
  registry_name = options.fetch(:name)
20
20
  workers = options.fetch(:workers, nil)
21
- workers ||= options.fetch(:size, nil)
22
21
 
23
22
  q = Queue.new(registry_name)
24
23
  q.register(klass, workers)
@@ -2,5 +2,4 @@ module SuckerPunch
2
2
  class Error < StandardError; end
3
3
  class MissingQueueName < Error; end
4
4
  class MissingWorkerName < Error; end
5
-
6
- end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module SuckerPunch
2
- VERSION = "0.4"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -15,14 +15,6 @@ describe SuckerPunch do
15
15
  queue name: :crazy_queue, worker: FakeWorker, workers: 3
16
16
  end
17
17
  end
18
-
19
- it "supports size for workers count" do
20
- SuckerPunch::Queue.any_instance.should_receive(:register).with(FakeWorker, 3)
21
-
22
- SuckerPunch.config do
23
- queue name: :crazy_queue, worker: FakeWorker, size: 3
24
- end
25
- end
26
18
  end
27
19
 
28
20
  context "with no queue name" do
data/sucker_punch.gemspec CHANGED
@@ -20,5 +20,5 @@ Gem::Specification.new do |gem|
20
20
  gem.add_development_dependency "rspec"
21
21
  gem.add_development_dependency "rake"
22
22
 
23
- gem.add_dependency "celluloid", "> 0.11"
23
+ gem.add_dependency "celluloid", "~> 0.13.0"
24
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sucker_punch
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-24 00:00:00.000000000 Z
12
+ date: 2013-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -48,17 +48,17 @@ dependencies:
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ! '>'
51
+ - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '0.11'
53
+ version: 0.13.0
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ! '>'
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0.11'
61
+ version: 0.13.0
62
62
  description: Asynchronous processing library for Ruby
63
63
  email:
64
64
  - brandonhilkert@gmail.com