rcelery 1.0.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.
- data/Gemfile +3 -0
- data/LICENSE +27 -0
- data/Rakefile +34 -0
- data/bin/rceleryd +7 -0
- data/lib/rcelery/async_result.rb +23 -0
- data/lib/rcelery/configuration.rb +25 -0
- data/lib/rcelery/daemon.rb +82 -0
- data/lib/rcelery/eager_result.rb +10 -0
- data/lib/rcelery/events.rb +103 -0
- data/lib/rcelery/pool.rb +59 -0
- data/lib/rcelery/rails.rb +29 -0
- data/lib/rcelery/railtie.rb +11 -0
- data/lib/rcelery/task/context.rb +25 -0
- data/lib/rcelery/task/runner.rb +73 -0
- data/lib/rcelery/task.rb +118 -0
- data/lib/rcelery/task_support.rb +56 -0
- data/lib/rcelery/version.rb +6 -0
- data/lib/rcelery/worker.rb +76 -0
- data/lib/rcelery.rb +86 -0
- data/rails/init.rb +4 -0
- data/rcelery.gemspec +28 -0
- data/spec/bin/ci +81 -0
- data/spec/integration/Procfile +4 -0
- data/spec/integration/bin/celeryd +4 -0
- data/spec/integration/bin/rabbitmq-server +4 -0
- data/spec/integration/bin/rceleryd +4 -0
- data/spec/integration/python_components/celery_client.py +5 -0
- data/spec/integration/python_components/celery_deferred_client.py +10 -0
- data/spec/integration/python_components/celeryconfig.py +26 -0
- data/spec/integration/python_components/requirements.txt +9 -0
- data/spec/integration/python_components/tasks.py +13 -0
- data/spec/integration/ruby_client_python_worker_spec.rb +17 -0
- data/spec/integration/ruby_worker_spec.rb +115 -0
- data/spec/integration/spec_helper.rb +43 -0
- data/spec/integration/tasks.rb +37 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/unit/configuration_spec.rb +91 -0
- data/spec/unit/daemon_spec.rb +21 -0
- data/spec/unit/eager_spec.rb +46 -0
- data/spec/unit/events_spec.rb +149 -0
- data/spec/unit/pool_spec.rb +124 -0
- data/spec/unit/rails_spec.rb +0 -0
- data/spec/unit/rcelery_spec.rb +154 -0
- data/spec/unit/task_spec.rb +192 -0
- data/spec/unit/task_support_spec.rb +94 -0
- data/spec/unit/worker_spec.rb +63 -0
- metadata +290 -0
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RCelery::Configuration do
|
4
|
+
before :each do
|
5
|
+
@config = RCelery::Configuration.new
|
6
|
+
end
|
7
|
+
it 'defaults the host to localhost' do
|
8
|
+
@config.host.should == 'localhost'
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'defaults the port to 5672' do
|
12
|
+
@config.port.should == 5672
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'defaults the vhost to /' do
|
16
|
+
@config.vhost.should == '/'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'defaults the username to guest' do
|
20
|
+
@config.username.should == 'guest'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'defaults the password to guest' do
|
24
|
+
@config.password.should == 'guest'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'defaults the application to application' do
|
28
|
+
@config.application.should == 'application'
|
29
|
+
end
|
30
|
+
|
31
|
+
# it 'defaults the worker count to 1' do
|
32
|
+
# @config.worker_count.should == 1
|
33
|
+
# end
|
34
|
+
|
35
|
+
it 'defaults eager mode to false' do
|
36
|
+
@config.eager_mode.should == false
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'overrides the default host when a hash is given to initialize' do
|
40
|
+
config = RCelery::Configuration.new(:host => 'otherhost')
|
41
|
+
config.host.should == 'otherhost'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'overrides the default port when a hash is given to initialize' do
|
45
|
+
config = RCelery::Configuration.new(:port => 1234)
|
46
|
+
config.port.should == 1234
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'overrides the default vhost when a hash is given to initialize' do
|
50
|
+
config = RCelery::Configuration.new(:vhost => '/different')
|
51
|
+
config.vhost.should == '/different'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'overrides the default username when a hash is given to initialize' do
|
55
|
+
config = RCelery::Configuration.new(:username => 'user')
|
56
|
+
config.username.should == 'user'
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'overrides the default password when a hash is given to initialize' do
|
60
|
+
config = RCelery::Configuration.new(:password => 'password')
|
61
|
+
config.password.should == 'password'
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'overrides the default application when a hash is given to initialize' do
|
65
|
+
config = RCelery::Configuration.new(:application => 'otherapp')
|
66
|
+
config.application.should == 'otherapp'
|
67
|
+
end
|
68
|
+
|
69
|
+
# it 'overrides the default worker count when a hash is given to initialize' do
|
70
|
+
# config = RCelery::Configuration.new(:worker_count => 23)
|
71
|
+
# config.worker_count.should == 23
|
72
|
+
# end
|
73
|
+
|
74
|
+
it 'overrides the eager mode setting' do
|
75
|
+
config = RCelery::Configuration.new(:eager_mode => true)
|
76
|
+
config.eager_mode.should == true
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'has a hash representation' do
|
80
|
+
@config.to_hash.should == {
|
81
|
+
:host => 'localhost',
|
82
|
+
:port => 5672,
|
83
|
+
:vhost => '/',
|
84
|
+
:username => 'guest',
|
85
|
+
:password => 'guest',
|
86
|
+
:application => 'application',
|
87
|
+
:worker_count => 1,
|
88
|
+
:eager_mode => false,
|
89
|
+
}
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RCelery::Daemon do
|
4
|
+
include RR::Adapters::RRMethods
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
# @channel, @queue = stub_amqp
|
8
|
+
end
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
RCelery.stop if RCelery.running?
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.new' do
|
15
|
+
it 'sets a config attr' do
|
16
|
+
d = RCelery::Daemon.new([])
|
17
|
+
d.instance_variable_get(:@config).should be_an_instance_of(RCelery::Configuration)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RCelery::Task do
|
4
|
+
module Tasks
|
5
|
+
include RCelery::TaskSupport
|
6
|
+
|
7
|
+
task(:name => 'different_name', :ignore_result => false)
|
8
|
+
def add(a,b, options = {})
|
9
|
+
noop(a + b + (options['c'] || 0))
|
10
|
+
end
|
11
|
+
|
12
|
+
task()
|
13
|
+
def ignore
|
14
|
+
'ignore_me'
|
15
|
+
end
|
16
|
+
|
17
|
+
def noop(val)
|
18
|
+
val
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
before :each do
|
23
|
+
@task = RCelery::Task.all_tasks['different_name']
|
24
|
+
end
|
25
|
+
|
26
|
+
after :each do
|
27
|
+
RCelery.stop
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#apply_async' do
|
31
|
+
it 'works with just args' do
|
32
|
+
RCelery.start(:eager_mode => true)
|
33
|
+
@task.apply_async(:args => [1,2]).wait.should == 3
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'works with args and kwargs' do
|
37
|
+
RCelery.start(:eager_mode => true)
|
38
|
+
@task.apply_async(:args => [1,2], :kwargs => {'c' => 1}).wait.should == 4
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'json encodes and decodes the args to mimic the over the wire process' do
|
42
|
+
RCelery.start(:eager_mode => true)
|
43
|
+
@task.apply_async(:args => [1,2], :kwargs => {:c => 1}).wait.should == 4
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RCelery::Events do
|
4
|
+
include RR::Adapters::RRMethods
|
5
|
+
|
6
|
+
describe "helper methods" do
|
7
|
+
|
8
|
+
describe ".hostname" do
|
9
|
+
it "returns the hostname" do
|
10
|
+
RCelery::Events.hostname.should == Socket.gethostname
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe ".timestamp" do
|
15
|
+
it "returns the time" do
|
16
|
+
stub(Time).now.returns(6)
|
17
|
+
RCelery::Events.timestamp.should == 6.0
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "event methods" do
|
24
|
+
|
25
|
+
before(:each) do
|
26
|
+
stub(RCelery::Events).timestamp.returns('the time')
|
27
|
+
stub(RCelery::Events).hostname.returns('hostname')
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '.task_received' do
|
31
|
+
it "publishes a task.received event" do
|
32
|
+
mock(RCelery).publish(:event, {
|
33
|
+
:type => 'task-received',
|
34
|
+
:uuid => 'uuid',
|
35
|
+
:name => 'name',
|
36
|
+
:args => 'args',
|
37
|
+
:kwargs => 'kwargs',
|
38
|
+
:retries => 'retries',
|
39
|
+
:eta => 'eta',
|
40
|
+
:hostname => 'hostname',
|
41
|
+
:timestamp => 'the time',
|
42
|
+
}, :routing_key => 'task.received')
|
43
|
+
RCelery::Events.task_received('uuid', 'name', 'args', 'kwargs', 'retries', 'eta')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.task_started' do
|
48
|
+
it "publishes a task.started event" do
|
49
|
+
mock(RCelery).publish(:event, {
|
50
|
+
:type => 'task-started',
|
51
|
+
:uuid => 'uuid',
|
52
|
+
:hostname => 'hostname',
|
53
|
+
:timestamp => 'the time',
|
54
|
+
:pid => 'pid',
|
55
|
+
}, :routing_key => 'task.started')
|
56
|
+
RCelery::Events.task_started('uuid', 'pid')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '.task_succeeded' do
|
61
|
+
it "publishes a task.succeeded event" do
|
62
|
+
mock(RCelery).publish(:event, {
|
63
|
+
:type => 'task-succeeded',
|
64
|
+
:uuid => 'uuid',
|
65
|
+
:result => 'result',
|
66
|
+
:hostname => 'hostname',
|
67
|
+
:timestamp => 'the time',
|
68
|
+
:runtime => 'runtime',
|
69
|
+
}, :routing_key => 'task.succeeded')
|
70
|
+
RCelery::Events.task_succeeded('uuid', 'result', 'runtime')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '.task_failed' do
|
75
|
+
it "publishes a task.failed event" do
|
76
|
+
mock(RCelery).publish(:event, {
|
77
|
+
:type => 'task-failed',
|
78
|
+
:uuid => 'uuid',
|
79
|
+
:exception => 'exception',
|
80
|
+
:traceback => 'traceback',
|
81
|
+
:hostname => 'hostname',
|
82
|
+
:timestamp => 'the time',
|
83
|
+
}, :routing_key => 'task.failed')
|
84
|
+
RCelery::Events.task_failed('uuid', 'exception', 'traceback')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '.task_retried' do
|
89
|
+
it "publishes a task.retried event" do
|
90
|
+
mock(RCelery).publish(:event, {
|
91
|
+
:type => 'task-retried',
|
92
|
+
:uuid => 'uuid',
|
93
|
+
:exception => 'exception',
|
94
|
+
:traceback => 'traceback',
|
95
|
+
:hostname => 'hostname',
|
96
|
+
:timestamp => 'the time',
|
97
|
+
}, :routing_key => 'task.retried')
|
98
|
+
RCelery::Events.task_retried('uuid', 'exception', 'traceback')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '.worker_online' do
|
103
|
+
it "publishes a worker.online event" do
|
104
|
+
mock(RCelery).publish(:event, {
|
105
|
+
:type => "worker-online",
|
106
|
+
:sw_ident => "rcelery",
|
107
|
+
:sw_ver => "1.0",
|
108
|
+
:sw_sys => RUBY_PLATFORM,
|
109
|
+
:hostname => 'hostname',
|
110
|
+
:timestamp => 'the time'
|
111
|
+
}, :routing_key => "worker.online")
|
112
|
+
|
113
|
+
RCelery::Events.worker_online("rcelery", "1.0", RUBY_PLATFORM)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '.worker_heartbeat' do
|
118
|
+
it 'publishes a worker.heartbeat event' do
|
119
|
+
mock(RCelery).publish(:event, {
|
120
|
+
:type => "worker-heartbeat",
|
121
|
+
:sw_ident => "rcelery",
|
122
|
+
:sw_ver => "1.0",
|
123
|
+
:sw_sys => RUBY_PLATFORM,
|
124
|
+
:hostname => 'hostname',
|
125
|
+
:timestamp => 'the time'
|
126
|
+
}, :routing_key => "worker.heartbeat")
|
127
|
+
|
128
|
+
RCelery::Events.worker_heartbeat("rcelery", "1.0", RUBY_PLATFORM)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe '.worker_offline' do
|
133
|
+
it 'publishes a worker.offline event' do
|
134
|
+
mock(RCelery).publish(:event, {
|
135
|
+
:type => "worker-offline",
|
136
|
+
:sw_ident => "rcelery",
|
137
|
+
:sw_ver => "1.0",
|
138
|
+
:sw_sys => RUBY_PLATFORM,
|
139
|
+
:hostname => 'hostname',
|
140
|
+
:timestamp => 'the time'
|
141
|
+
}, :routing_key => "worker.offline")
|
142
|
+
|
143
|
+
RCelery::Events.worker_offline("rcelery", "1.0", RUBY_PLATFORM)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RCelery::Pool do
|
4
|
+
include RR::Adapters::RRMethods
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@channel, @queue = stub_amqp
|
8
|
+
end
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
RCelery.stop if RCelery.running?
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.new' do
|
15
|
+
it 'starts RCelery if it is not running' do
|
16
|
+
mock.proxy(RCelery).start({:host => 'option'})
|
17
|
+
RCelery::Pool.new({:host => 'option'})
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'does not start RCelery if it is running' do
|
21
|
+
RCelery.start
|
22
|
+
dont_allow(RCelery).start({:some => 'option'})
|
23
|
+
RCelery::Pool.new(:some => 'option')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '.start' do
|
28
|
+
it 'subscribes to the request queue' do
|
29
|
+
mock(@queue).subscribe(:ack => true)
|
30
|
+
RCelery::Pool.new.start
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '.stop' do
|
35
|
+
it 'unsubscribes from the queue' do
|
36
|
+
pool = RCelery::Pool.new
|
37
|
+
pool.start
|
38
|
+
mock(@queue).unsubscribe
|
39
|
+
pool.stop
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '.subscribe' do
|
44
|
+
it 'adds tasks to the task queue' do
|
45
|
+
pool = RCelery::Pool.new
|
46
|
+
|
47
|
+
message = {
|
48
|
+
:id => "blah",
|
49
|
+
:task => "blah task",
|
50
|
+
:args => [],
|
51
|
+
:kwargs => {}
|
52
|
+
}
|
53
|
+
|
54
|
+
stub(@queue).subscribe.yields("hello", message.to_json)
|
55
|
+
stub(RCelery::Events).task_received
|
56
|
+
|
57
|
+
pool.start
|
58
|
+
|
59
|
+
expected_message = {
|
60
|
+
"id" => "blah",
|
61
|
+
"task" => "blah task",
|
62
|
+
"args" => [],
|
63
|
+
"kwargs" => {}
|
64
|
+
}
|
65
|
+
|
66
|
+
pool.poll.should == {:message => expected_message, :header => "hello"}
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'sends a task received event with the correct information' do
|
70
|
+
pool = RCelery::Pool.new
|
71
|
+
|
72
|
+
message = {
|
73
|
+
:id => "blah",
|
74
|
+
:task => "this.task",
|
75
|
+
:args => [1,2,3],
|
76
|
+
:kwargs => {:this => "that"}
|
77
|
+
}
|
78
|
+
|
79
|
+
stub(@queue).subscribe.yields("hello", message.to_json)
|
80
|
+
mock(RCelery::Events).task_received("blah", "this.task", [1,2,3], {"this" => "that"}, nil, nil)
|
81
|
+
pool.start
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'defers a task if the eta is in the future' do
|
85
|
+
pool = RCelery::Pool.new
|
86
|
+
tomorrow = DateTime.now.next
|
87
|
+
|
88
|
+
message = {
|
89
|
+
:id => "blah",
|
90
|
+
:task => "this.task",
|
91
|
+
:args => "hi",
|
92
|
+
:kwargs => "kwargs",
|
93
|
+
:eta => tomorrow.to_s
|
94
|
+
}
|
95
|
+
|
96
|
+
stub(@queue).subscribe.yields("hello", message.to_json)
|
97
|
+
stub(RCelery::Events).task_received
|
98
|
+
|
99
|
+
expected_message = {
|
100
|
+
"id" => "blah",
|
101
|
+
"task" => "this.task",
|
102
|
+
"args" => "hi",
|
103
|
+
"kwargs" => "kwargs",
|
104
|
+
"eta" => tomorrow.to_s
|
105
|
+
}
|
106
|
+
|
107
|
+
mock(pool).defer({:message => expected_message, :header => "hello"})
|
108
|
+
pool.start
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'acks messages that fail parsing' do
|
112
|
+
pool = RCelery::Pool.new
|
113
|
+
|
114
|
+
header = mock!
|
115
|
+
mock(header).ack
|
116
|
+
stub(@queue).subscribe.yields(header, "{blah")
|
117
|
+
|
118
|
+
pool.start
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
end
|
File without changes
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RCelery do
|
4
|
+
before :each do
|
5
|
+
stub(AMQP).start
|
6
|
+
stub(AMQP).stop
|
7
|
+
|
8
|
+
@options = { :host => 'host', :port => 1234, :application => 'some_app' }
|
9
|
+
@channel, @queue = stub_amqp
|
10
|
+
end
|
11
|
+
|
12
|
+
after :each do
|
13
|
+
RCelery.stop if RCelery.running?
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.start' do
|
17
|
+
it 'starts amqp with the connection string based on the options passed less the application option' do
|
18
|
+
stub(RCelery).channel { @channel }
|
19
|
+
mock(AMQP).start(hash_including({
|
20
|
+
:host => 'host',
|
21
|
+
:port => 1234,
|
22
|
+
:username => 'guest',
|
23
|
+
:password => 'guest',
|
24
|
+
:vhost => '/'
|
25
|
+
}))
|
26
|
+
|
27
|
+
RCelery.start(@options)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "doesn't start AMQP if the connection is connected" do
|
31
|
+
stub(RCelery).channel { @channel }
|
32
|
+
connection = stub!.connected? { true }.subject
|
33
|
+
stub(AMQP).connection { connection }
|
34
|
+
|
35
|
+
RCelery.thread.should be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'sets up the request, results and event exchanges' do
|
39
|
+
channel = mock!.direct('celery', :durable => true) { 'request exchange' }.subject
|
40
|
+
mock(channel).direct('celeryresults', :durable => true, :auto_delete => true) { 'results exchange' }
|
41
|
+
mock(channel).topic('celeryev', :durable => true) { 'events exchange' }
|
42
|
+
stub(channel).queue { @queue }
|
43
|
+
|
44
|
+
stub(RCelery).channel { channel }
|
45
|
+
|
46
|
+
RCelery.start(@options)
|
47
|
+
|
48
|
+
RCelery.exchanges[:request].should == 'request exchange'
|
49
|
+
RCelery.exchanges[:result].should == 'results exchange'
|
50
|
+
RCelery.exchanges[:event].should == 'events exchange'
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'sets up the request queue and binds it to the request exchange correctly' do
|
54
|
+
stub(@channel).direct('celery', anything) { 'request exchange' }
|
55
|
+
mock(@channel).queue('rcelery.some_app', :durable => true) { @queue }
|
56
|
+
mock(@queue).bind('request exchange', :routing_key => 'rcelery.some_app') { @queue }
|
57
|
+
stub(RCelery).channel { @channel }
|
58
|
+
RCelery.start(@options)
|
59
|
+
|
60
|
+
RCelery.queue.should == @queue
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'sets the running flag to true after completion' do
|
64
|
+
stub(RCelery).channel { @channel }
|
65
|
+
|
66
|
+
RCelery.running?.should be_false
|
67
|
+
RCelery.start(@options)
|
68
|
+
RCelery.running?.should be_true
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns the self object (RCelery)' do
|
72
|
+
stub(RCelery).channel { @channel }
|
73
|
+
RCelery.start(@options).should == RCelery
|
74
|
+
end
|
75
|
+
|
76
|
+
it "doesn't start anything if eager_mode is set" do
|
77
|
+
RCelery.start(@options.merge(:eager_mode => true))
|
78
|
+
RCelery.running?.should be_true
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '.stop' do
|
83
|
+
before :each do
|
84
|
+
stub(RCelery).channel { @channel }
|
85
|
+
RCelery.start(@options)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'stops AMQP' do
|
89
|
+
mock(AMQP).stop
|
90
|
+
|
91
|
+
RCelery.stop
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'updates various pieces of internal state:' do
|
95
|
+
before :each do
|
96
|
+
RCelery.stop
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'sets the running state to false' do
|
100
|
+
RCelery.running?.should be_false
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'clears the exchanges' do
|
104
|
+
RCelery.exchanges.should be_nil
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'clears the thread' do
|
108
|
+
RCelery.thread.should be_nil
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'clears the request queue' do
|
112
|
+
RCelery.queue.should be_nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '.publish' do
|
118
|
+
it 'publishes a message to the exchange specified, calling to_json first' do
|
119
|
+
exchange = mock!.publish('some message'.to_json, anything).subject
|
120
|
+
stub(@channel).direct('celery', anything) { exchange }
|
121
|
+
stub(RCelery).channel { @channel }
|
122
|
+
RCelery.start(@options)
|
123
|
+
|
124
|
+
RCelery.publish(:request, 'some message', {:some => 'option'})
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'uses the application name as the routing key if none is given' do
|
128
|
+
exchange = mock!.publish(anything, hash_including({:routing_key => 'rcelery.some_app'})).subject
|
129
|
+
stub(@channel).direct('celery', anything) { exchange }
|
130
|
+
stub(RCelery).channel { @channel }
|
131
|
+
RCelery.start(@options)
|
132
|
+
|
133
|
+
RCelery.publish(:request, 'some message', {:some => 'option'})
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'publishes the message with the application/json content_type' do
|
137
|
+
exchange = mock!.publish(anything, hash_including({:content_type => 'application/json'})).subject
|
138
|
+
stub(@channel).direct('celery', anything) { exchange }
|
139
|
+
stub(RCelery).channel { @channel }
|
140
|
+
RCelery.start(@options)
|
141
|
+
|
142
|
+
RCelery.publish(:request, 'some message', {:some => 'option'})
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'passes any options to the exchange' do
|
146
|
+
exchange = mock!.publish(anything, hash_including({:some => 'option'})).subject
|
147
|
+
stub(@channel).direct('celery', anything) { exchange }
|
148
|
+
stub(RCelery).channel { @channel }
|
149
|
+
RCelery.start(@options)
|
150
|
+
|
151
|
+
RCelery.publish(:request, 'some message', {:some => 'option'})
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|