sucker_punch 1.4.0 → 1.5.0

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: 063fd2167ea7931708d817864a566519fed44bc4
4
- data.tar.gz: 90c335d21c42d04a3b83ff4c58aa336dbdcff216
3
+ metadata.gz: dfa2c3188160d11c140e02f6935357ef0cdf8dc7
4
+ data.tar.gz: a9bfa22e4f43208aee4a6cc660db600d1be62c49
5
5
  SHA512:
6
- metadata.gz: bdedb891160c8569ee0e022d4f4dbd501306cdc2e6f27dba368ca027a86fc13a147834438c392a1ab60b7f34716effb0c6fd8dfe548953f46e3dc239a62bccb0
7
- data.tar.gz: 999af4061d5ec40a10bcc6efd65effacfea1565c17fcf8b736638af5504e0c234e686dd9ad3e81b4f7e9470afdbf83d2416fd5e741fe092f3def99e7d960c094
6
+ metadata.gz: eba72894093e01f2fd3900c548c14d4c68deec3da4f248ffc3577dceb99247ea9505f122d0c74fc419a34ee7d269a2368a7d7a91ce64a1a41dcbc7e873e1a0cb
7
+ data.tar.gz: 2ba835f123989034ec6a86f06ec0d5ec336991808e4c3c98b25f7d7afa7e82c8194b144d4fbc6829284b6321804e6b8f50c2252e25223e299b649c6dafdf66c7
data/CHANGES.md CHANGED
@@ -1,3 +1,9 @@
1
+ 1.5.0
2
+ --------
3
+
4
+ - Allow number of workers to be up to and including 200
5
+ - Don't clear out non-Sucker Punch Celluloid registry on boot [#113](https://github.com/brandonhilkert/sucker_punch/pull/113)
6
+
1
7
  1.4.0
2
8
  --------
3
9
 
data/README.md CHANGED
@@ -145,6 +145,22 @@ SuckerPunch.logger # => #<Logger:0x007fa1f28b83f0>
145
145
  _Note: If Sucker Punch is being used within a Rails application, Sucker Punch's logger
146
146
  is set to Rails.logger by default._
147
147
 
148
+ ## Exceptions
149
+
150
+ You can customize how to handle uncaught exceptions that are raised by your jobs.
151
+
152
+ For example, using Rails and the ExceptionNotification gem, add a new initializer `config/initializers/sucker_punch.rb`:
153
+
154
+ ```Ruby
155
+ SuckerPunch.exception_handler { |ex| ExceptionNotifier.notify_exception(ex) }
156
+ ```
157
+
158
+ Or, using Airbrake:
159
+
160
+ ```Ruby
161
+ SuckerPunch.exception_handler { |ex| Airbrake.notify(ex) }
162
+ ```
163
+
148
164
  ## Testing
149
165
 
150
166
  Requiring this library causes your jobs to run everything inline. So a call to the following will actually be SYNCHRONOUS:
@@ -16,6 +16,10 @@ module SuckerPunch
16
16
  def self.exception_handler(&block)
17
17
  Celluloid.exception_handler(&block)
18
18
  end
19
+
20
+ def self.clear_queues
21
+ SuckerPunch::Queue.clear_all
22
+ end
19
23
  end
20
24
 
21
25
  require 'sucker_punch/railtie' if defined?(::Rails)
@@ -6,6 +6,7 @@ module SuckerPunch
6
6
  attr_accessor :pool
7
7
 
8
8
  DEFAULT_OPTIONS = { workers: 2 }
9
+ PREFIX = "sucker_punch"
9
10
  class MaxWorkersExceeded < StandardError; end
10
11
  class NotEnoughWorkers < StandardError; end
11
12
 
@@ -14,6 +15,17 @@ module SuckerPunch
14
15
  Celluloid::Actor[queue.name]
15
16
  end
16
17
 
18
+ def self.clear_all
19
+ Celluloid::Actor.all.each do |actor|
20
+ registered_name = actor.registered_name.to_s
21
+ matches = registered_name.match(PREFIX).to_a
22
+
23
+ if matches.any?
24
+ Celluloid::Actor.delete(registered_name)
25
+ end
26
+ end
27
+ end
28
+
17
29
  def initialize(klass)
18
30
  @klass = klass
19
31
  @pool = nil
@@ -22,7 +34,7 @@ module SuckerPunch
22
34
 
23
35
  def register(num_workers = DEFAULT_OPTIONS[:workers])
24
36
  num_workers ||= DEFAULT_OPTIONS[:workers]
25
- raise MaxWorkersExceeded if num_workers > 100
37
+ raise MaxWorkersExceeded if num_workers > 200
26
38
  raise NotEnoughWorkers if num_workers < 1
27
39
 
28
40
  @mutex.synchronize {
@@ -39,7 +51,8 @@ module SuckerPunch
39
51
  end
40
52
 
41
53
  def name
42
- klass.to_s.underscore.to_sym
54
+ klass_name = klass.to_s.underscore
55
+ "#{PREFIX}_#{klass_name}".to_sym
43
56
  end
44
57
 
45
58
  private
@@ -5,7 +5,7 @@ module SuckerPunch
5
5
  end
6
6
 
7
7
  config.to_prepare do
8
- Celluloid::Actor.clear_registry
8
+ SuckerPunch.clear_queues
9
9
  end
10
10
  end
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module SuckerPunch
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -15,7 +15,7 @@ describe SuckerPunch::Queue do
15
15
  Celluloid::Actor.clear_registry
16
16
  end
17
17
 
18
- describe "#find" do
18
+ describe ".find" do
19
19
  it "returns the Celluloid Actor from the registry" do
20
20
  SuckerPunch::Queue.new(FakeJob).register
21
21
  queue = SuckerPunch::Queue.find(FakeJob)
@@ -23,6 +23,32 @@ describe SuckerPunch::Queue do
23
23
  end
24
24
  end
25
25
 
26
+ describe ".clear_all" do
27
+ it "removes SuckerPunch actors from Celluloid registry" do
28
+ sucker_punch_actor_name = "#{SuckerPunch::Queue::PREFIX}_fake_job".to_sym
29
+ Celluloid::Actor[sucker_punch_actor_name] = FakeJob.new
30
+
31
+ SuckerPunch::Queue.clear_all
32
+
33
+ expect(Celluloid::Actor[sucker_punch_actor_name]).to be_nil
34
+ end
35
+
36
+ it "does not remove non-SuckerPunch actors from Celluloid registry" do
37
+ class ::OtherJob
38
+ include ::Celluloid
39
+ def self.pool(options); end
40
+ def perform; end
41
+ end
42
+ actor_name = :other_job
43
+ job = OtherJob.new
44
+ Celluloid::Actor[actor_name] = job
45
+
46
+ SuckerPunch::Queue.clear_all
47
+
48
+ expect(Celluloid::Actor[actor_name]).to eq job
49
+ end
50
+ end
51
+
26
52
  describe "#register" do
27
53
  let(:job) { FakeJob }
28
54
  let(:queue) { SuckerPunch::Queue.new(job) }
@@ -33,18 +59,24 @@ describe SuckerPunch::Queue do
33
59
  end
34
60
 
35
61
  it "registers the pool with Celluloid" do
62
+ expected_pool_name = "#{SuckerPunch::Queue::PREFIX}_fake_job".to_sym
63
+
36
64
  pool = queue.register
37
- expect(Celluloid::Actor[:fake_job]).to eq(pool)
65
+
66
+ expect(Celluloid::Actor[expected_pool_name]).to eq(pool)
38
67
  end
39
68
 
40
69
  it "registers the pool with Celluloid and 3 workers" do
41
- pool = queue.register(3)
42
- expect(Celluloid::Actor[:fake_job].size).to eq(3)
70
+ expected_pool_name = "#{SuckerPunch::Queue::PREFIX}_fake_job"
71
+
72
+ queue.register(3)
73
+
74
+ expect(Celluloid::Actor[expected_pool_name].size).to eq(3)
43
75
  end
44
76
 
45
77
  context "when too many workers are specified" do
46
78
  it "raises a MaxWorkersExceeded exception" do
47
- expect{ queue.register(101) }.to raise_error(SuckerPunch::Queue::MaxWorkersExceeded)
79
+ expect{ queue.register(201) }.to raise_error(SuckerPunch::Queue::MaxWorkersExceeded)
48
80
  end
49
81
  end
50
82
 
@@ -11,4 +11,14 @@ describe SuckerPunch do
11
11
  SuckerPunch.logger = nil
12
12
  end
13
13
  end
14
+
15
+ describe '.clear_queues' do
16
+ it "clears SuckerPunch queues" do
17
+ allow(SuckerPunch::Queue).to receive(:clear_all)
18
+
19
+ SuckerPunch.clear_queues
20
+
21
+ expect(SuckerPunch::Queue).to have_received(:clear_all)
22
+ end
23
+ end
14
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sucker_punch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Hilkert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-07 00:00:00.000000000 Z
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec