magellan-rails 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/Gemfile +11 -0
- data/lib/magellan/rails/version.rb +1 -1
- data/lib/magellan/worker/core.rb +19 -2
- data/spec/magellan/worker/core_spec.rb +25 -2
- data/spec/spec_helper.rb +8 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cc3c3d99017ab1ddca401772a150619a9e760a0
|
4
|
+
data.tar.gz: 0e473c7599532b9ae3570cd586e3950204322379
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e812b06bfe2bec1d7d8d4d08516b1eb3bde553daf8dda04ee8091e737c30751b5a6a0a70f113a53140ce30b121714aabe92eb7d26ce06a692900a4cd4c31e8eb
|
7
|
+
data.tar.gz: 5ca87553e052d1da2f5f128b311a73eb33f04800bed2fc68955d9631dce7220823cc307682c6bbda1e94b5765b213354d6812db2a1437bafb2307e12aa0a12f8
|
data/.rspec
ADDED
data/Gemfile
CHANGED
@@ -5,3 +5,14 @@ gem "bunny_mock", :git => 'git://github.com/groovenauts/bunny-mock.git',
|
|
5
5
|
|
6
6
|
# Specify your gem's dependencies in magellan-rails.gemspec
|
7
7
|
gemspec
|
8
|
+
|
9
|
+
group :development, :test do
|
10
|
+
gem "rspec-mocks"
|
11
|
+
gem "simplecov"
|
12
|
+
gem "fuubar"
|
13
|
+
if RUBY_VERSION.split(".", 2)[0].to_i >= 2
|
14
|
+
gem "pry-byebug"
|
15
|
+
else
|
16
|
+
gem "pry-debugger"
|
17
|
+
end
|
18
|
+
end
|
data/lib/magellan/worker/core.rb
CHANGED
@@ -41,13 +41,23 @@ class Magellan::Worker::Core
|
|
41
41
|
|
42
42
|
@executor = Magellan::Worker::Executor.new(@exchange)
|
43
43
|
|
44
|
+
@shutdown = false
|
45
|
+
|
44
46
|
self
|
45
47
|
end
|
46
48
|
|
49
|
+
def shutdown
|
50
|
+
@channel && @channel.work_pool.shutdown
|
51
|
+
@shutdown = true
|
52
|
+
end
|
53
|
+
|
47
54
|
def run
|
55
|
+
# reset for re-run
|
56
|
+
@shutdown = false
|
57
|
+
|
48
58
|
# handle SIGTERM from `docker stop`
|
49
|
-
Signal.trap(:TERM) do
|
50
|
-
|
59
|
+
@original_trap_handler = Signal.trap(:TERM) do
|
60
|
+
shutdown
|
51
61
|
end
|
52
62
|
|
53
63
|
Magellan.logger.info("====== Magellan Worker start ======")
|
@@ -70,7 +80,14 @@ class Magellan::Worker::Core
|
|
70
80
|
rescue
|
71
81
|
Magellan.logger.error("Magellan Worker request execution error: #{$!}\n" + $@.join("\n"))
|
72
82
|
end
|
83
|
+
if @shutdown
|
84
|
+
delivery_info.consumer.cancel
|
85
|
+
end
|
73
86
|
end
|
74
87
|
Magellan.logger.info("====== Magellan Worker finished ======")
|
88
|
+
ensure
|
89
|
+
if @original_trap_handler
|
90
|
+
Signal.trap(:TERM, @original_trap_handler)
|
91
|
+
end
|
75
92
|
end
|
76
93
|
end
|
@@ -34,11 +34,13 @@ describe Magellan::Worker::Core do
|
|
34
34
|
queue = channel.queue("consumer1.sample_project.1.0.0.rails")
|
35
35
|
queue.bind(exchange)
|
36
36
|
exchange.publish(@request_message.to_json, routing_key: "1.0.0.rails", reply_to: 'reply_test', correlation_id: "correlation_id_sample")
|
37
|
+
@work_pool = double "work_pool"
|
37
38
|
|
38
39
|
allow(Bunny ).to receive(:new).and_return(bunny)
|
39
40
|
allow(bunny ).to receive(:create_channel).and_return(channel)
|
40
41
|
allow(channel).to receive(:queue).with('customer1.sample_project.1.0.0.rails', no_declare: true).and_return(queue)
|
41
42
|
allow(channel).to receive(:basic_ack).and_return(queue)
|
43
|
+
allow(channel).to receive(:work_pool).and_return(@work_pool)
|
42
44
|
|
43
45
|
config = {}
|
44
46
|
config[:host] = '127.0.0.1'
|
@@ -63,8 +65,29 @@ describe Magellan::Worker::Core do
|
|
63
65
|
subject.run
|
64
66
|
expect(Magellan.logger ).to be_a(Logger)
|
65
67
|
end
|
66
|
-
end
|
67
|
-
|
68
68
|
|
69
|
+
describe "gracefully shutdown" do
|
70
|
+
before do
|
71
|
+
@consumer = double(:consumer)
|
72
|
+
expect_any_instance_of(BunnyMock::DeliveryInfo).to receive(:consumer).and_return(@consumer)
|
73
|
+
expect(@consumer).to receive(:cancel)
|
74
|
+
end
|
75
|
+
it do
|
76
|
+
expect(Magellan::Worker::Config).to receive(:load_config).once
|
77
|
+
expect(@work_pool).to receive(:shutdown).once
|
78
|
+
# store local variable to be referenced in module_eval block
|
79
|
+
core = subject()
|
80
|
+
# FIXME: RSpec3 mock obsolete and_return{ ... } feature and it seems no alternatives.
|
81
|
+
# Re-define `execute` method to emulate signal handling during the method execution.
|
82
|
+
@executor.singleton_class.module_eval do
|
83
|
+
define_method(:execute) do |*args|
|
84
|
+
core.shutdown
|
85
|
+
nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
subject.run
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
69
92
|
end
|
70
93
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
+
if ENV["COVERAGE"].to_s =~ /true|yes|on|1/i
|
2
|
+
require "simplecov"
|
3
|
+
SimpleCov.start "rails"
|
4
|
+
end
|
5
|
+
|
1
6
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
7
|
require 'magellan/worker'
|
3
8
|
require 'magellan/rails'
|
4
9
|
require 'magellan/subscriber'
|
10
|
+
require "rspec"
|
11
|
+
require "rspec/mocks"
|
12
|
+
require "pry"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magellan-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuuki Noguchi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -89,6 +89,7 @@ extensions: []
|
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
91
|
- ".gitignore"
|
92
|
+
- ".rspec"
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE.txt
|
94
95
|
- README.md
|
@@ -152,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
153
|
version: '0'
|
153
154
|
requirements: []
|
154
155
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
156
|
+
rubygems_version: 2.4.5
|
156
157
|
signing_key:
|
157
158
|
specification_version: 4
|
158
159
|
summary: ''
|