gruf 2.1.1 → 2.2.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
- SHA1:
3
- metadata.gz: 53a6a934e512aeba4261172db33d22e9994ede7f
4
- data.tar.gz: 5fb09d8483bd0ff4d22f759ab9ae442b3f4e63cb
2
+ SHA256:
3
+ metadata.gz: 5e2128aead5d95df32a7c576007e1f725321d994a30dcc799369ef04a2866bae
4
+ data.tar.gz: 9cce18e801ce59b8d156f9f02fdb0266281bea439cd6da85e94d7a0c6ca45df1
5
5
  SHA512:
6
- metadata.gz: 6f8ff602e9d5a53eface3706b55546dd83f964cae57a20d1dc41d74aa6770a6f06d67a3a1aa0c040f3091b03cc3a132bca6d83ed3eb5351ee0520b7c480d6c0f
7
- data.tar.gz: a44dd99112b76fa2f5116a6418cc80a90c5c7ff8a1ad8a4c45e03bcd384172ced2221d60daf7614c2a022f107b2fdd19e0d786c84dfb4ea9c3a4b1f090f3fbc5
6
+ metadata.gz: 47e56d29f46dbdd51634bff6c2cba63b482e99ab94a57022e231bd4d081f8b26efcefa524712dd3a9faf0edc9aeddc07895b01a1acf51b9f24f512657faba61d
7
+ data.tar.gz: e3b9a9e56016f3ede0520bfc4fafd1f9409c32ea16a977ca27f6c296d0215d26ec9f1d8de705659710da855f22de6083c0681cdc5b974ef80b2602144892f488
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@ Changelog for the gruf gem. This includes internal history before the gem was ma
2
2
 
3
3
  ### Pending release
4
4
 
5
+ ### 2.2.0
6
+
7
+ - Run server in a monitored thread to allow for trapped exits on sigints
8
+
5
9
  ### 2.1.1
6
10
 
7
11
  - Add ability to pass in client stub options into Gruf::Client
data/README.md CHANGED
@@ -17,9 +17,9 @@ up fast and efficiently at scale. Some of its features include:
17
17
  still preserving gRPC BadStatus codes
18
18
  * Server and client execution timings in responses
19
19
 
20
- gruf currently has active support for gRPC 1.4.x-1.8.x. gruf is compatible and tested with Ruby 2.2,
21
- 2.3, and 2.4. gruf is also not [Rails](https://github.com/rails/rails)-specific, and can be used in any
22
- Ruby framework (such as [Grape](https://github.com/ruby-grape/grape), for instance).
20
+ gruf currently has active support for gRPC 1.4.x-1.9.x. gruf is compatible and tested with Ruby 2.2-2.5.
21
+ gruf is also not [Rails](https://github.com/rails/rails)-specific, and can be used in any Ruby framework
22
+ (such as [Grape](https://github.com/ruby-grape/grape), for instance).
23
23
 
24
24
  ## Installation
25
25
 
data/lib/gruf/server.rb CHANGED
@@ -39,7 +39,10 @@ module Gruf
39
39
  @interceptors = Gruf::Interceptors::Registry.new unless @interceptors.is_a?(Gruf::Interceptors::Registry)
40
40
  @services = []
41
41
  @started = false
42
- setup!
42
+ @stop_server = false
43
+ @stop_server_cv = ConditionVariable.new
44
+ @stop_server_mu = Monitor.new
45
+ setup
43
46
  end
44
47
 
45
48
  ##
@@ -58,18 +61,25 @@ module Gruf
58
61
  # Start the gRPC server
59
62
  #
60
63
  # :nocov:
61
- # rubocop:disable Lint/ShadowedException
62
64
  def start!
65
+ stop_server_thread = Thread.new do
66
+ loop do
67
+ break if @stop_server
68
+ @stop_server_mu.synchronize { @stop_server_cv.wait(@stop_server_mu, 10) }
69
+ end
70
+ logger.info { 'Shutting down...' }
71
+ server.stop
72
+ end
73
+
63
74
  logger.info { 'Booting gRPC Server...' }
64
75
  @started = true
65
- server.run_till_terminated
66
- rescue Interrupt, SignalException, SystemExit
67
- logger.info { 'Shutting down gRPC server...' }
76
+ server.run
77
+ stop_server_thread.join
68
78
  @started = false
69
- server.stop
79
+
80
+ logger.info { 'Goodbye!' }
70
81
  end
71
82
  # :nocov:
72
- # rubocop:enable Lint/ShadowedException
73
83
 
74
84
  ##
75
85
  # @param [Class] klass
@@ -139,11 +149,40 @@ module Gruf
139
149
 
140
150
  private
141
151
 
152
+ ##
153
+ # Setup server
154
+ #
155
+ # :nocov:
156
+ def setup
157
+ setup_signal_handlers
158
+ load_controllers
159
+ end
160
+ # :nocov:
161
+
162
+ ##
163
+ # Register signal handlers
164
+ #
165
+ # :nocov:
166
+ def setup_signal_handlers
167
+ Thread.abort_on_exception = true
168
+
169
+ Signal.trap('INT') do
170
+ @stop_server = true
171
+ @stop_server_cv.broadcast
172
+ end
173
+
174
+ Signal.trap('TERM') do
175
+ @stop_server = true
176
+ @stop_server_cv.broadcast
177
+ end
178
+ end
179
+ # :nocov:
180
+
142
181
  ##
143
182
  # Auto-load all gRPC handlers
144
183
  #
145
184
  # :nocov:
146
- def setup!
185
+ def load_controllers
147
186
  return unless File.directory?(controllers_path)
148
187
  path = File.realpath(controllers_path)
149
188
  $LOAD_PATH.unshift(path)
data/lib/gruf/version.rb CHANGED
@@ -14,5 +14,5 @@
14
14
  # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
15
  #
16
16
  module Gruf
17
- VERSION = '2.1.1'.freeze
17
+ VERSION = '2.2.0'.freeze
18
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gruf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun McCormick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-01 00:00:00.000000000 Z
11
+ date: 2018-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  version: '0'
159
159
  requirements: []
160
160
  rubyforge_project:
161
- rubygems_version: 2.6.14
161
+ rubygems_version: 2.7.6
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: gRPC Ruby Framework