sucker_punch 1.0.0.beta → 1.0.0.beta2
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/CHANGES.md +6 -1
- data/README.md +16 -0
- data/lib/sucker_punch/job.rb +9 -3
- data/lib/sucker_punch/queue.rb +6 -4
- data/lib/sucker_punch/version.rb +1 -1
- data/spec/sucker_punch/job_spec.rb +20 -12
- data/spec/sucker_punch/queue_spec.rb +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9d68b7c7b9b1609f465227f56920578ca0cd037
|
4
|
+
data.tar.gz: 561bf68629e9c4fc95b3156d29c168e081f85bcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04688497fae792eb3bedd54c34261848632e18b956e2fe3fb539e4c9fee229a2c062745eede2f99359c3723b00eded0f065d4965597609a750125151f46d534a
|
7
|
+
data.tar.gz: 7b579b1302292f6d36848f7a805dbe47d4b0521892b8b892d8821b2cdf7d46497b5a42450dfdb9c07459fdd9db90ddeb63a2a622c00bc8bf4ab591055d900404
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -86,6 +86,22 @@ 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
|
+
|
91
|
+
|
92
|
+
```Ruby
|
93
|
+
class LogJob
|
94
|
+
include SuckerPunch::Job
|
95
|
+
workers 4
|
96
|
+
|
97
|
+
def perform(event)
|
98
|
+
Log.new(event).track
|
99
|
+
end
|
100
|
+
end
|
101
|
+
```
|
102
|
+
|
103
|
+
If the `workers` method is not set, it is by default set to 2.
|
104
|
+
|
89
105
|
## Logger
|
90
106
|
|
91
107
|
```Ruby
|
data/lib/sucker_punch/job.rb
CHANGED
@@ -5,15 +5,21 @@ module SuckerPunch
|
|
5
5
|
base.extend(ClassMethods)
|
6
6
|
|
7
7
|
base.class_eval do
|
8
|
+
@workers = SuckerPunch::Queue::DEFAULT_OPTIONS[:workers]
|
9
|
+
|
8
10
|
def self.new
|
9
|
-
define_celluloid_pool(self)
|
11
|
+
define_celluloid_pool(self, @workers)
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
16
|
module ClassMethods
|
15
|
-
def
|
16
|
-
|
17
|
+
def workers(num)
|
18
|
+
@workers = num
|
19
|
+
end
|
20
|
+
|
21
|
+
def define_celluloid_pool(klass, workers)
|
22
|
+
SuckerPunch::Queue.new(klass).register(workers)
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
data/lib/sucker_punch/queue.rb
CHANGED
@@ -5,6 +5,8 @@ module SuckerPunch
|
|
5
5
|
attr_reader :klass
|
6
6
|
attr_accessor :pool
|
7
7
|
|
8
|
+
DEFAULT_OPTIONS = { workers: 2 }
|
9
|
+
|
8
10
|
def self.find(klass)
|
9
11
|
queue = self.new(klass)
|
10
12
|
Celluloid::Actor[queue.name]
|
@@ -16,10 +18,10 @@ module SuckerPunch
|
|
16
18
|
@mutex = Mutex.new
|
17
19
|
end
|
18
20
|
|
19
|
-
def register
|
21
|
+
def register(workers = DEFAULT_OPTIONS[:workers] )
|
20
22
|
@mutex.synchronize {
|
21
23
|
unless registered?
|
22
|
-
initialize_celluloid_pool
|
24
|
+
initialize_celluloid_pool(workers)
|
23
25
|
register_celluloid_pool
|
24
26
|
register_queue_with_master_list
|
25
27
|
end
|
@@ -37,8 +39,8 @@ module SuckerPunch
|
|
37
39
|
|
38
40
|
private
|
39
41
|
|
40
|
-
def initialize_celluloid_pool
|
41
|
-
self.pool = klass.send(:pool)
|
42
|
+
def initialize_celluloid_pool(workers)
|
43
|
+
self.pool = klass.send(:pool, { size: workers })
|
42
44
|
end
|
43
45
|
|
44
46
|
def register_celluloid_pool
|
data/lib/sucker_punch/version.rb
CHANGED
@@ -4,6 +4,7 @@ describe SuckerPunch::Job do
|
|
4
4
|
before :each do
|
5
5
|
class ::FakeJob
|
6
6
|
include SuckerPunch::Job
|
7
|
+
workers 4
|
7
8
|
|
8
9
|
def perform(name)
|
9
10
|
"response #{name}"
|
@@ -11,24 +12,31 @@ describe SuckerPunch::Job do
|
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
15
|
+
after :each do
|
16
|
+
Celluloid::Actor.clear_registry
|
17
|
+
end
|
18
|
+
|
14
19
|
it "includes Celluloid into requesting class when included" do
|
15
20
|
FakeJob.should respond_to(:pool)
|
16
21
|
end
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
expect(SuckerPunch::Queues.all).to eq([])
|
23
|
+
it "sets the pool size to 4" do
|
24
|
+
pool = FakeJob.new
|
25
|
+
expect(pool.size).to eq(4)
|
26
|
+
end
|
23
27
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
it "returns the same pool on each instantiation" do
|
29
|
+
pool = FakeJob.new
|
30
|
+
pool2 = FakeJob.new
|
31
|
+
expect(pool.thread).to eq(pool2.thread)
|
32
|
+
end
|
28
33
|
|
29
|
-
|
30
|
-
|
31
|
-
|
34
|
+
describe "when pool hasn't been created" do
|
35
|
+
it "registers queue" do
|
36
|
+
queue = stub("queue")
|
37
|
+
SuckerPunch::Queue.stub(new: queue)
|
38
|
+
queue.should_receive(:register).with(4)
|
39
|
+
pool = FakeJob.new
|
32
40
|
end
|
33
41
|
end
|
34
42
|
end
|
@@ -33,6 +33,11 @@ describe SuckerPunch::Queue do
|
|
33
33
|
expect(Celluloid::Actor[:fake_job]).to eq(pool)
|
34
34
|
end
|
35
35
|
|
36
|
+
it "registers the pool with Celluloid" do
|
37
|
+
pool = queue.register(3)
|
38
|
+
expect(Celluloid::Actor[:fake_job].size).to eq(3)
|
39
|
+
end
|
40
|
+
|
36
41
|
it "registers with master list of queues" do
|
37
42
|
queue.register
|
38
43
|
queues = SuckerPunch::Queues.all
|
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.0.0.
|
4
|
+
version: 1.0.0.beta2
|
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-07-
|
11
|
+
date: 2013-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|