protein 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/protein/amqp_adapter.rb +23 -0
- data/lib/protein/server.rb +16 -7
- data/lib/protein/version.rb +1 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b2d385b542b3564b97860e18f7eb1f00526c2ed
|
4
|
+
data.tar.gz: 6804a4443e61e4c186bf949bb85fb9830fabbf28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81de7fe02a5df4411a3d8cf154dc4b38f2d94f2249594b5c8dec201507cfebffb02ae7c1d0486d003974feab5daa4e67ca677e4f5b05ab9db76cc7c8f25c00af
|
7
|
+
data.tar.gz: e0fc17fe57afb3bd2445d29130d495446d8ecb5fee7216fedfc5138a92ee49d8daa2bcdd8835df2e8ed4a261192303b043a76e32e94fb95bd7560ba8c812eae1
|
data/lib/protein/amqp_adapter.rb
CHANGED
@@ -78,6 +78,8 @@ class AMQPAdapter
|
|
78
78
|
|
79
79
|
def serve(router)
|
80
80
|
@conn = Bunny.new(url)
|
81
|
+
@terminating = false
|
82
|
+
@processing = false
|
81
83
|
begin
|
82
84
|
@conn.start
|
83
85
|
rescue Bunny::TCPConnectionFailed => e
|
@@ -90,11 +92,28 @@ class AMQPAdapter
|
|
90
92
|
@q = @ch.queue(queue)
|
91
93
|
@x = @ch.default_exchange
|
92
94
|
|
95
|
+
Signal.trap("TERM") do
|
96
|
+
if @processing
|
97
|
+
@terminating = true
|
98
|
+
else
|
99
|
+
exit
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
Signal.trap("INT") do
|
104
|
+
if @processing
|
105
|
+
@terminating = true
|
106
|
+
else
|
107
|
+
exit
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
93
111
|
Protein.logger.info "Connected to #{url}, serving RPC calls from #{queue}"
|
94
112
|
|
95
113
|
loop do
|
96
114
|
begin
|
97
115
|
@q.subscribe(block: true, manual_ack: true) do |delivery_info, properties, payload|
|
116
|
+
@processing = true
|
98
117
|
begin
|
99
118
|
@error = nil
|
100
119
|
response = Processor.call(router, payload)
|
@@ -110,12 +129,16 @@ class AMQPAdapter
|
|
110
129
|
end
|
111
130
|
|
112
131
|
@ch.ack(delivery_info.delivery_tag)
|
132
|
+
@processing = false
|
133
|
+
break if @terminating
|
113
134
|
if @error
|
114
135
|
log_error(@error)
|
115
136
|
raise(@error)
|
116
137
|
end
|
117
138
|
end
|
118
139
|
rescue StandardError => e
|
140
|
+
@processing = false
|
141
|
+
break if @terminating
|
119
142
|
log_error(e)
|
120
143
|
Protein.logger.error "RPC server error: #{e.inspect}, restarting the server in 5s..."
|
121
144
|
|
data/lib/protein/server.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'parallel'
|
2
|
-
|
3
1
|
module Protein
|
4
2
|
class Server
|
5
3
|
class << self
|
@@ -29,19 +27,30 @@ class Server
|
|
29
27
|
GetConst.call(@transport_class)
|
30
28
|
end
|
31
29
|
|
30
|
+
|
32
31
|
def start
|
33
32
|
worker_count = config.fetch(:concurrency, 5)
|
34
33
|
on_worker_boot = config[:on_worker_boot]
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
Protein.logger.info "Starting server #{
|
35
|
+
pids = (1..worker_count).map do |i|
|
36
|
+
fork do
|
37
|
+
Protein.logger.info "Starting server #{i}/#{worker_count} with PID #{Process.pid}"
|
39
38
|
on_worker_boot.call if on_worker_boot.respond_to?(:call)
|
40
39
|
transport_class.serve(router)
|
41
40
|
end
|
42
|
-
else
|
43
|
-
transport_class.serve(router)
|
44
41
|
end
|
42
|
+
|
43
|
+
Signal.trap('TERM') do
|
44
|
+
pids.each { |pid| Process.kill(:TERM, pid) }
|
45
|
+
pids.each { |pid| Process.wait(pid) }
|
46
|
+
end
|
47
|
+
|
48
|
+
Signal.trap('INT') do
|
49
|
+
pids.each { |pid| Process.kill(:INT, pid) }
|
50
|
+
pids.each { |pid| Process.wait(pid) }
|
51
|
+
end
|
52
|
+
|
53
|
+
Process.wait
|
45
54
|
end
|
46
55
|
end
|
47
56
|
end
|
data/lib/protein/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protein
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karol Słuszniak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -58,20 +58,6 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '3.0'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: parallel
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '1.0'
|
68
|
-
type: :runtime
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - "~>"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '1.0'
|
75
61
|
description:
|
76
62
|
email: karol@shedul.com
|
77
63
|
executables: []
|