sucker_punch 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 993f07c48fd24506ec4f6233b141142a3d4584bf
4
- data.tar.gz: 19e5a661fabd7053db509438cd49980d7260e75b
3
+ metadata.gz: 3176eeae888f0de8b24a633fd09eb3bd1a903b75
4
+ data.tar.gz: 6ed863474d1d0efdb0009a40a440b424f6e6656e
5
5
  SHA512:
6
- metadata.gz: e8bad658a733babb44d0fb0e8e680bc7b7e23e5e70a1dd2d37c0d23d0d5f3f81d79f7be7cdef5babffe51ac80171a87079aaa64942cbbf1c4499aad07b8142f4
7
- data.tar.gz: 967146bea4c03054314035ebb06e0eb0a70a355c4042fed10c0d276942172e52670183fffa2c41106a7faf6fe591e2a0056b2cabad91d48b198b129c8e32b1e6
6
+ metadata.gz: deb547d6b67c54576d1f2398abec30356dfa9f324e793190396b67e47f460048accdf1160810201505366b3ad7a76a3c3429afb71a5b234f0d0fd4a1d173cdb7
7
+ data.tar.gz: 0ca6cddc806a3a6cffbfb58b2f0254b68875a08a703717cc173e622677f865d95b32540ba3710bb5ef1a3af37e059ea9a9fa6f4e41eda22fb8b89ec3313e6d05
data/.travis.yml CHANGED
@@ -2,5 +2,9 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - jruby-19mode
5
- - rbx-19mode
5
+ - rbx
6
6
  - 2.0.0
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: jruby-19mode
10
+ - rvm: rbx
data/README.md CHANGED
@@ -86,8 +86,7 @@ class AwesomeJob
86
86
  end
87
87
  ```
88
88
 
89
- The number of workers that get created can be set from the Job using the `workers` method:
90
-
89
+ The number of workers can be set from the Job using the `workers` method:
91
90
 
92
91
  ```Ruby
93
92
  class LogJob
@@ -100,16 +99,41 @@ class LogJob
100
99
  end
101
100
  ```
102
101
 
103
- If the `workers` method is not set, it is by default set to 2.
102
+ If the `workers` method is not set, the default is `2`.
103
+
104
+ ## Perform In
105
+
106
+ Many background processing libraries have methods to perform operations after a
107
+ certain amount of time. Fortunately, timers are built-in to Celluloid, so you
108
+ can take advantage of them with the `after` method:
109
+
110
+ ``` ruby
111
+ class Job
112
+ include SuckerPunch::Job
113
+
114
+ def perform(data)
115
+ sleep 2
116
+ puts data
117
+ end
118
+
119
+ def later(sec, data)
120
+ after(sec) { perform(data) }
121
+ end
122
+ end
123
+
124
+ Job.new.async.perform("asdf")
125
+ Job.new.async.later(60, "asdf") # `perform` will be excuted 60 sec. later
126
+ ```
104
127
 
105
128
  ## Logger
106
129
 
107
130
  ```Ruby
108
- SuckerPunch.logger = Logger.new('sucker_punch')
131
+ SuckerPunch.logger = Logger.new('sucker_punch.log')
109
132
  SuckerPunch.logger # => #<Logger:0x007fa1f28b83f0>
110
133
  ```
111
134
 
112
- If Sucker Punch is being used within a Rails application, Sucker Punch's logger is set to Rails.logger by default.
135
+ _Note: If Sucker Punch is being used within a Rails application, Sucker Punch's logger
136
+ is set to Rails.logger by default._
113
137
 
114
138
  ## Testing
115
139
 
@@ -128,15 +152,17 @@ Log.new.async.perform("login") # => Will be synchronous and block until job is f
128
152
 
129
153
  ### Initializers for forking servers (Unicorn, Passenger, etc.)
130
154
 
131
- Previously, Sucker Punch required an initializer and that posed problems for Unicorn and Passenger and other servers that fork.
132
- Version 1 was rewritten to not require any special code to be executed after forking occurs. Please remove all of that if you're
133
- using version `>= 1.0.0`
155
+ Previously, Sucker Punch required an initializer and that posed problems for
156
+ Unicorn and Passenger and other servers that fork. Version 1 was rewritten to
157
+ not require any special code to be executed after forking occurs. Please remove
158
+ if you're using version `>= 1.0.0`
134
159
 
135
160
  ### Class naming
136
161
 
137
- Job classes are ultimately Celluloid Actor classes. As a result, class names are susceptible to being clobbered by Celluloid's internal classes.
138
- To ensure the intended application class is loaded, preface classes with `::`, or use names like `NotificationsMailer` or
139
- `UserMailer`. Example:
162
+ Job classes are ultimately Celluloid Actor classes. As a result, class names
163
+ are susceptible to being clobbered by Celluloid's internal classes. To ensure
164
+ the intended application class is loaded, preface classes with `::`, or use
165
+ names like `NotificationsMailer` or `UserMailer`. Example:
140
166
 
141
167
  ```Ruby
142
168
  class EmailJob
@@ -151,7 +177,7 @@ end
151
177
 
152
178
  ### Cleaning test data transactions
153
179
 
154
- If you're running tests in transactions (using Database Cleaner or a native solution), Sucker Punch jobs may have trouble finding database records that were created during test setup because the job class is running in a separate thread and the Transaction operates on a different thread so it clears out the data before the jojob can do its business. The best thing to do is cleanup data created for tests jobs through a truncation strategy by tagging the rspec tests as jobs and then specifying the strategy in `spec_helper` like below:
180
+ If you're running tests in transactions (using Database Cleaner or a native solution), Sucker Punch jobs may have trouble finding database records that were created during test setup because the job class is running in a separate thread and the Transaction operates on a different thread so it clears out the data before the job can do its business. The best thing to do is cleanup data created for tests jobs through a truncation strategy by tagging the rspec tests as jobs and then specifying the strategy in `spec_helper` like below:
155
181
 
156
182
  ```Ruby
157
183
  # spec/spec_helper.rb
@@ -161,7 +187,7 @@ RSpec.configure do |config|
161
187
  end
162
188
 
163
189
  # Clean up all jobs specs with truncation
164
- config.before(:each, :job => true) do
190
+ config.before(:each, job: true) do
165
191
  DatabaseCleaner.strategy = :truncation
166
192
  end
167
193
 
@@ -172,6 +198,7 @@ RSpec.configure do |config|
172
198
  config.after(:each) do
173
199
  DatabaseCleaner.clean
174
200
  end
201
+ end
175
202
 
176
203
  # spec/jobs/email_job_spec.rb
177
204
  require 'spec_helper'
@@ -192,7 +219,9 @@ end
192
219
 
193
220
  ## Gem Name
194
221
 
195
- ...is awesome. But I can't take credit for it. Thanks to [@jmazzi](https://twitter.com/jmazzi) for his superior naming skills. If you're looking for a name for something, he is the one to go to.
222
+ ...is awesome. But I can't take credit for it. Thanks to
223
+ [@jmazzi](https://twitter.com/jmazzi) for his superior naming skills. If you're
224
+ looking for a name for something, he is the one to go to.
196
225
 
197
226
  ## Contributing
198
227
 
@@ -201,3 +230,4 @@ end
201
230
  3. Commit your changes (`git commit -am 'Add some feature'`)
202
231
  4. Push to the branch (`git push origin my-new-feature`)
203
232
  5. Create new Pull Request
233
+
@@ -29,14 +29,13 @@ module SuckerPunch
29
29
  unless registered?
30
30
  initialize_celluloid_pool(num_workers)
31
31
  register_celluloid_pool
32
- register_queue_with_master_list
33
32
  end
34
33
  }
35
34
  self.class.find(klass)
36
35
  end
37
36
 
38
37
  def registered?
39
- SuckerPunch::Queues.all.include?(name)
38
+ Celluloid::Actor.registered.include?(name.to_sym)
40
39
  end
41
40
 
42
41
  def name
@@ -52,10 +51,6 @@ module SuckerPunch
52
51
  def register_celluloid_pool
53
52
  Celluloid::Actor[name] = pool
54
53
  end
55
-
56
- def register_queue_with_master_list
57
- SuckerPunch::Queues.register(name)
58
- end
59
54
  end
60
55
  end
61
56
 
@@ -2,6 +2,10 @@ module SuckerPunch
2
2
  class Railtie < ::Rails::Railtie
3
3
  initializer "sucker_punch.logger" do
4
4
  SuckerPunch.logger = Rails.logger
5
+
6
+ ActionDispatch::Reloader.to_prepare do
7
+ Celluloid::Actor.clear_registry
8
+ end
5
9
  end
6
10
  end
7
11
  end
@@ -1,3 +1,3 @@
1
1
  module SuckerPunch
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -11,6 +11,10 @@ describe SuckerPunch::Queue do
11
11
  end
12
12
  end
13
13
 
14
+ after :each do
15
+ Celluloid::Actor.clear_registry
16
+ end
17
+
14
18
  describe "#find" do
15
19
  it "returns the Celluloid Actor from the registry" do
16
20
  SuckerPunch::Queue.new(FakeJob).register
@@ -33,17 +37,11 @@ describe SuckerPunch::Queue do
33
37
  expect(Celluloid::Actor[:fake_job]).to eq(pool)
34
38
  end
35
39
 
36
- it "registers the pool with Celluloid" do
40
+ it "registers the pool with Celluloid and 3 workers" do
37
41
  pool = queue.register(3)
38
42
  expect(Celluloid::Actor[:fake_job].size).to eq(3)
39
43
  end
40
44
 
41
- it "registers with master list of queues" do
42
- queue.register
43
- queues = SuckerPunch::Queues.all
44
- expect(queues.size).to be(1)
45
- end
46
-
47
45
  context "when too many workers are specified" do
48
46
  it "raises a MaxWorkersExceeded exception" do
49
47
  expect{ queue.register(101) }.to raise_error(SuckerPunch::Queue::MaxWorkersExceeded)
data/sucker_punch.gemspec CHANGED
@@ -21,5 +21,5 @@ Gem::Specification.new do |gem|
21
21
  gem.add_development_dependency "rake"
22
22
  gem.add_development_dependency "pry"
23
23
 
24
- gem.add_dependency "celluloid", "~> 0.15.1"
24
+ gem.add_dependency "celluloid", "~> 0.15.2"
25
25
  end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sucker_punch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Hilkert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-06 00:00:00.000000000 Z
11
+ date: 2014-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: celluloid
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.15.1
61
+ version: 0.15.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.15.1
68
+ version: 0.15.2
69
69
  description: Asynchronous processing library for Ruby
70
70
  email:
71
71
  - brandonhilkert@gmail.com
@@ -73,8 +73,8 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - .gitignore
77
- - .travis.yml
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
78
  - CHANGES.md
79
79
  - Gemfile
80
80
  - LICENSE.txt
@@ -150,17 +150,17 @@ require_paths:
150
150
  - lib
151
151
  required_ruby_version: !ruby/object:Gem::Requirement
152
152
  requirements:
153
- - - '>='
153
+ - - ">="
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  requirements:
158
- - - '>='
158
+ - - ">="
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  requirements: []
162
162
  rubyforge_project:
163
- rubygems_version: 2.0.2
163
+ rubygems_version: 2.2.2
164
164
  signing_key:
165
165
  specification_version: 4
166
166
  summary: Sucker Punch is a Ruby asynchronous processing using Celluloid, heavily influenced