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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63cf837ff41c8be4608441605bbf5a5c5f45e249
4
- data.tar.gz: 72555ef175c6637a367c976de3c2ae69ef4fd237
3
+ metadata.gz: 7b2d385b542b3564b97860e18f7eb1f00526c2ed
4
+ data.tar.gz: 6804a4443e61e4c186bf949bb85fb9830fabbf28
5
5
  SHA512:
6
- metadata.gz: 7311e2ac8421b6c332823732e925e6a64070b1cc59d1417ba90205fd025896cb7d6056c5e839586e49cbf30e21714ad61d800e8122a9c8a3c3bc90e2559ed164
7
- data.tar.gz: b235f39f076c6d7e9ecd88bb1958bd82314bee737b0eb479ed4653e91b69c76363ff5003cba6784fa2b9ffc64b1ee86a207e8b911fe3b1cee839a93c8e6b3372
6
+ metadata.gz: 81de7fe02a5df4411a3d8cf154dc4b38f2d94f2249594b5c8dec201507cfebffb02ae7c1d0486d003974feab5daa4e67ca677e4f5b05ab9db76cc7c8f25c00af
7
+ data.tar.gz: e0fc17fe57afb3bd2445d29130d495446d8ecb5fee7216fedfc5138a92ee49d8daa2bcdd8835df2e8ed4a261192303b043a76e32e94fb95bd7560ba8c812eae1
@@ -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
 
@@ -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
- if worker_count.is_a?(Integer) && worker_count > 1
37
- Parallel.each(1..worker_count, in_processes: worker_count) do |worker|
38
- Protein.logger.info "Starting server #{worker}/#{worker_count} with PID #{Process.pid}"
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
@@ -1,3 +1,3 @@
1
1
  module Protein
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
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.6.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: 2018-11-08 00:00:00.000000000 Z
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: []