qusion 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,12 +10,12 @@ module Qusion
10
10
  attr_reader :thread
11
11
  end
12
12
 
13
- def self.start(*opts)
13
+ def self.start(*opts, &block)
14
14
  amqp_opts = AmqpConfig.new(*opts).config_opts
15
- start_amqp_dispatcher(amqp_opts)
15
+ start_amqp_dispatcher(amqp_opts, &block)
16
16
  end
17
17
 
18
- def self.start_amqp_dispatcher(amqp_settings={})
18
+ def self.start_amqp_dispatcher(amqp_settings={}, &block)
19
19
  AMQP.settings.merge!(amqp_settings)
20
20
 
21
21
  if defined?(::PhusionPassenger) && ::PhusionPassenger.respond_to?(:on_event)
@@ -26,13 +26,13 @@ module Qusion
26
26
  Thread.current[:mq] = nil
27
27
  AMQP.instance_variable_set(:@conn, nil)
28
28
  end
29
- start_in_background
29
+ start_in_background(&block)
30
30
  die_gracefully_on_signal
31
31
  end
32
32
  return
33
33
  end
34
34
 
35
- start_in_background
35
+ start_in_background(&block)
36
36
  die_gracefully_on_signal
37
37
  end
38
38
 
@@ -49,14 +49,14 @@ module Qusion
49
49
  ChannelPool.pool_size = new_pool_size
50
50
  end
51
51
 
52
- def self.start_in_background
52
+ def self.start_in_background(&block)
53
53
  if EM.reactor_running?
54
54
  raise ArgumentError, 'AMQP already connected' if ready_to_dispatch?
55
- AMQP.start
55
+ AMQP.start(&block)
56
56
  else
57
57
  raise ArgumentError, 'Qusion already started' if thread && thread.alive?
58
58
  @thread = Thread.new do
59
- EM.run { AMQP.start }
59
+ EM.run { AMQP.start(&block) }
60
60
  raise "Premature AMQP shutdown" unless @graceful_stop
61
61
  end
62
62
  thread.abort_on_exception = true
@@ -1,3 +1,3 @@
1
1
  module Qusion
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
- require File.dirname(__FILE__) + "/../../spec_helper"
3
- require File.dirname(__FILE__) + "/../../stub_rails"
2
+ require "spec_helper"
3
+ require "stub_rails"
4
4
 
5
5
  describe AmqpConfig do
6
6
 
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
- require File.dirname(__FILE__) + "/../../spec_helper"
2
+ require "spec_helper"
3
3
 
4
4
  describe ChannelPool do
5
5
  MQ = Object.new
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
- require File.dirname(__FILE__) + "/../../spec_helper"
2
+ require "spec_helper"
3
3
 
4
4
  describe "Qusion Convenience Methods" do
5
5
 
@@ -47,27 +47,43 @@ describe Qusion, 'amqp startup' do
47
47
  amqp_conn.should_receive(:connected?).and_return(false)
48
48
  AMQP.should_receive(:conn).any_number_of_times.and_return(amqp_conn)
49
49
  EM.should_receive(:stop)
50
- AMQP.should_receive(:start).once
51
- Qusion.start_amqp_dispatcher
50
+
51
+ block = proc { nil }
52
+ AMQP.should_receive(:start).with(&block).once
53
+
54
+ Qusion.start_amqp_dispatcher(&block)
52
55
  end
53
56
 
54
- it "should set AMQP's connection settings when running under Thin" do
55
- Qusion.should_receive(:die_gracefully_on_signal)
56
- Qusion.should_receive(:start_in_background)
57
- ::Thin = Module.new
57
+ it "should set AMQP's connection settings" do
58
+ Qusion.stub(:die_gracefully_on_signal)
59
+ Qusion.stub(:start_in_background)
58
60
  Qusion.start_amqp_dispatcher(:cookie => "yummy")
59
61
  AMQP.settings[:cookie].should == "yummy"
60
62
  end
61
63
 
62
- it "should start a worker thread when running under Mongrel" do
63
- Qusion.should_receive(:die_gracefully_on_signal)
64
- mock_thread = mock('thread')
65
- mock_thread.should_receive(:abort_on_exception=).with(true)
66
- Qusion.should_receive(:ready_to_dispatch?).twice.and_return(false, true)
67
- mock_thread.should_receive(:join)
68
- Thread.should_receive(:new).and_return(mock_thread)
69
- ::Mongrel = Module.new
70
- Qusion.start_amqp_dispatcher
64
+ it "should start a worker thread when the EM reactor isn't running" do
65
+ EM.stub(:reactor_running? => false)
66
+ Qusion.stub(:die_gracefully_on_signal)
67
+ Qusion.stub(:ready_to_dispatch?).twice.and_return(false, true)
68
+
69
+ block = proc { nil }
70
+
71
+ AMQP.should_receive(:start).with(&block)
72
+
73
+ Qusion.start_amqp_dispatcher(&block)
74
+
75
+ Qusion.thread.should be_a(Thread)
76
+ Qusion.thread.abort_on_exception.should be_true
77
+ Qusion.thread.kill
78
+ end
79
+
80
+ it 'should start up AMQP when the EM reactor is running' do
81
+ block = proc { nil }
82
+ EM.stub(:reactor_running? => true)
83
+ Thread.should_not_receive(:new)
84
+ AMQP.should_receive(:start).with(&block)
85
+
86
+ Qusion.start_amqp_dispatcher(&block)
71
87
  end
72
88
 
73
89
  it "should be ready to dispatch when the reactor is running and amqp is connected" do
@@ -78,4 +94,4 @@ describe Qusion, 'amqp startup' do
78
94
  Qusion.ready_to_dispatch?.should == true
79
95
  end
80
96
 
81
- end
97
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: qusion
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.8
5
+ version: 0.1.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dan DeLeo
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2011-05-25 00:00:00 -04:00
15
+ date: 2011-07-16 00:00:00 -04:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -72,7 +72,6 @@ files:
72
72
  - .gemtest
73
73
  - .gitignore
74
74
  - Gemfile
75
- - Gemfile.lock
76
75
  - LICENSE
77
76
  - README.md
78
77
  - Rakefile