sucker_punch 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sucker_punch.rb +8 -12
- data/lib/sucker_punch/queue.rb +15 -3
- data/lib/sucker_punch/version.rb +1 -1
- data/spec/queue_spec.rb +18 -0
- data/spec/sucker_punch_spec.rb +4 -13
- metadata +1 -1
data/lib/sucker_punch.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'celluloid'
|
2
2
|
require 'sucker_punch/exceptions'
|
3
|
+
require 'sucker_punch/queue'
|
4
|
+
require 'sucker_punch/worker'
|
5
|
+
require 'sucker_punch/version'
|
3
6
|
|
4
7
|
module SuckerPunch
|
5
8
|
extend self
|
@@ -9,21 +12,14 @@ module SuckerPunch
|
|
9
12
|
end
|
10
13
|
|
11
14
|
def queue(options = {})
|
12
|
-
raise
|
13
|
-
raise
|
15
|
+
raise MissingQueueName unless options[:name]
|
16
|
+
raise MissingWorkerName unless options[:worker]
|
14
17
|
|
15
18
|
klass = options.fetch(:worker)
|
16
19
|
registry_name = options.fetch(:name)
|
17
20
|
size = options.fetch(:size, nil)
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
else
|
22
|
-
klass.send(:pool)
|
23
|
-
end
|
22
|
+
q = Queue.new(registry_name)
|
23
|
+
q.register(klass, size)
|
24
24
|
end
|
25
|
-
end
|
26
|
-
|
27
|
-
require 'sucker_punch/queue'
|
28
|
-
require 'sucker_punch/worker'
|
29
|
-
require 'sucker_punch/version'
|
25
|
+
end
|
data/lib/sucker_punch/queue.rb
CHANGED
@@ -1,9 +1,21 @@
|
|
1
1
|
module SuckerPunch
|
2
|
-
|
3
|
-
|
2
|
+
class Queue
|
3
|
+
attr_reader :name
|
4
4
|
|
5
|
-
def
|
5
|
+
def initialize(name)
|
6
|
+
@name = name
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.[](name)
|
6
10
|
Celluloid::Actor[name]
|
7
11
|
end
|
12
|
+
|
13
|
+
def register(klass, size)
|
14
|
+
Celluloid::Actor[name] = if size
|
15
|
+
klass.send(:pool, size: size)
|
16
|
+
else
|
17
|
+
klass.send(:pool)
|
18
|
+
end
|
19
|
+
end
|
8
20
|
end
|
9
21
|
end
|
data/lib/sucker_punch/version.rb
CHANGED
data/spec/queue_spec.rb
CHANGED
@@ -3,6 +3,9 @@ require 'spec_helper'
|
|
3
3
|
class FakeWorker
|
4
4
|
include Celluloid
|
5
5
|
end
|
6
|
+
class FakeOtherWorker
|
7
|
+
include Celluloid
|
8
|
+
end
|
6
9
|
|
7
10
|
describe SuckerPunch::Queue do
|
8
11
|
describe ".[]" do
|
@@ -12,4 +15,19 @@ describe SuckerPunch::Queue do
|
|
12
15
|
SuckerPunch::Queue[:fake]
|
13
16
|
end
|
14
17
|
end
|
18
|
+
|
19
|
+
describe "#register" do
|
20
|
+
before(:each) do
|
21
|
+
SuckerPunch::Queue.new(:crazy_queue).register(FakeWorker, 7)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "turns the class into an actor" do
|
25
|
+
Celluloid::Actor[:crazy_queue].should be_a(FakeWorker)
|
26
|
+
Celluloid::Actor[:crazy_queue].methods.should include(:async)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "sets worker size" do
|
30
|
+
Celluloid::Actor[:crazy_queue].size.should == 7
|
31
|
+
end
|
32
|
+
end
|
15
33
|
end
|
data/spec/sucker_punch_spec.rb
CHANGED
@@ -6,24 +6,15 @@ end
|
|
6
6
|
|
7
7
|
describe SuckerPunch do
|
8
8
|
context "config" do
|
9
|
+
|
9
10
|
context "properly configured" do
|
10
|
-
|
11
|
+
it "registers the queue" do
|
12
|
+
SuckerPunch::Queue.any_instance.should_receive(:register).with(FakeWorker, 7)
|
13
|
+
|
11
14
|
SuckerPunch.config do
|
12
15
|
queue name: :crazy_queue, worker: FakeWorker, size: 7
|
13
16
|
end
|
14
17
|
end
|
15
|
-
|
16
|
-
it "turns the class into an actor" do
|
17
|
-
Celluloid::Actor[:crazy_queue].should be_a(FakeWorker)
|
18
|
-
Celluloid::Actor[:crazy_queue].methods.should include(:async)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "allow asynchrounous processing" do
|
22
|
-
end
|
23
|
-
|
24
|
-
it "sets worker size" do
|
25
|
-
Celluloid::Actor[:crazy_queue].size.should == 7
|
26
|
-
end
|
27
18
|
end
|
28
19
|
|
29
20
|
context "with no queue name" do
|