gruf 1.2.5 → 1.2.6

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: 7765e1ba50ecdc417020e4083e304f900845fa1b
4
- data.tar.gz: e615c4331dac126796b304c0056070de88faeb15
3
+ metadata.gz: 475f72d5e3590bcbdbc32f8698bf835540c964c1
4
+ data.tar.gz: 877dd14c01855fba9e2006bf50df04b07cfbb804
5
5
  SHA512:
6
- metadata.gz: 2372e9d8ebd9d18edad57ba5985af76e28b9062503cd4c53658d5eb0b765c96a0a28a29ef50da0dd832607f7c9046a75560cd357ed0aee3cb229c33250bdf2d9
7
- data.tar.gz: 3d8e0d3d1632f31c2e0838b2e1469059bebc5ce7fc8b153becffe51d29bd96d2b4997cfd115b98c6f8ae6aa5626d0b179cc4b31f3c0865f42cd0f2e9ea748e61
6
+ metadata.gz: 2451565946bade99073f6dc7d567d623761a2f35a6c7541fdfc6dd431c29046635e057a1da9441390cbae5e32c8a6eb85e8a913ea851a9f7cc3079ea8971d4e1
7
+ data.tar.gz: 95d1fe70fde36eb85fae02c97cb518277f0d182f8d7bb5f659125b5d6bbcfa390e09707379c8969144384f34be782715d52c145ec83945bb37834f69405cf1be
@@ -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
+ ### 1.2.6
6
+
7
+ - Fix issues with arity and bidirectional streaming
8
+
5
9
  ### 1.2.5
6
10
 
7
11
  - Fix reference issue for client and bidirectional streaming calls
@@ -89,7 +89,7 @@ module Gruf
89
89
  # @return [Gruf::Response] The response from the server
90
90
  # @raise [Gruf::Client::Error|GRPC::BadStatus] If an error occurs, an exception will be raised according to the
91
91
  # error type that was returned
92
- def call(request_method, params = {}, metadata = {}, opts = {})
92
+ def call(request_method, params = {}, metadata = {}, opts = {}, &block)
93
93
  request_method = request_method.to_sym
94
94
  req = streaming_request?(request_method) ? params : request_object(request_method, params)
95
95
  md = build_metadata(metadata)
@@ -97,11 +97,16 @@ module Gruf
97
97
 
98
98
  raise NotImplementedError, "The method #{request_method} has not been implemented in this service." unless call_sig
99
99
 
100
- execute(call_sig, req, md, opts)
100
+ resp = execute(call_sig, req, md, opts, &block)
101
+
102
+ Gruf::Response.new(resp.result, resp.time)
101
103
  rescue GRPC::BadStatus => e
102
104
  emk = Gruf.error_metadata_key.to_s
103
105
  raise Gruf::Client::Error, error_deserializer_class.new(e.metadata[emk]).deserialize if e.respond_to?(:metadata) && e.metadata.key?(emk)
104
106
  raise # passthrough
107
+ rescue => e
108
+ Gruf.logger.error e.message
109
+ raise
105
110
  end
106
111
 
107
112
  private
@@ -123,13 +128,12 @@ module Gruf
123
128
  # @param [Hash] md (Optional) A hash of metadata key/values that are transported with the client request
124
129
  # @param [Hash] opts (Optional) A hash of options to send to the gRPC request_response method
125
130
  #
126
- def execute(call_sig, req, md, opts = {})
127
- timed = Timer.time do
131
+ def execute(call_sig, req, md, opts = {}, &block)
132
+ Timer.time do
128
133
  opts[:return_op] = true
129
134
  opts[:metadata] = md
130
- send(call_sig, req, opts)
135
+ send(call_sig, req, opts, &block)
131
136
  end
132
- Gruf::Response.new(timed.result, timed.time)
133
137
  end
134
138
 
135
139
  ##
@@ -25,6 +25,8 @@ module Gruf
25
25
  # @return [Array<Class>] The services this server is handling
26
26
  attr_accessor :services
27
27
 
28
+ attr_reader :server
29
+
28
30
  ##
29
31
  # Initialize the server and load and setup the services
30
32
  #
@@ -35,17 +37,26 @@ module Gruf
35
37
  load_services(services)
36
38
  end
37
39
 
40
+ ##
41
+ # @return [GRPC::RpcServer] The GRPC server running
42
+ #
43
+ def server
44
+ unless @server
45
+ @server = GRPC::RpcServer.new(Gruf.server_options)
46
+ @server.add_http2_port(Gruf.server_binding_url, ssl_credentials)
47
+ services.each do |s|
48
+ @server.handle(s)
49
+ end
50
+ end
51
+ @server
52
+ end
53
+
38
54
  ##
39
55
  # Start the gRPC server
40
56
  #
41
57
  # :nocov:
42
58
  def start!
43
59
  logger.info { 'Booting gRPC Server...' }
44
- server = GRPC::RpcServer.new(Gruf.server_options)
45
- server.add_http2_port Gruf.server_binding_url, ssl_credentials
46
- services.each do |s|
47
- server.handle(s)
48
- end
49
60
  server.run_till_terminated
50
61
  logger.info { 'Shutting down gRPC server...' }
51
62
  end
@@ -36,12 +36,37 @@ module Gruf
36
36
  return if @__last_methods_added && @__last_methods_added.include?(method_name)
37
37
  return unless rpc_handler_names.include?(method_name)
38
38
 
39
+ rpc_desc = rpc_descs[method_name.to_s.camelcase.to_sym]
40
+
39
41
  with = :"#{method_name}_with_intercept"
40
42
  without = :"#{method_name}_without_intercept"
41
43
  @__last_methods_added = [method_name, with, without]
42
- define_method with do |*args, &block|
43
- call_chain(method_name, args[0], args[1], &block)
44
+
45
+ if rpc_desc
46
+ if rpc_desc.request_response?
47
+ define_method(with) do |request, call|
48
+ call_chain(method_name, request, call)
49
+ end
50
+ elsif rpc_desc.client_streamer?
51
+ define_method(with) do |call|
52
+ call_chain(method_name, nil, call)
53
+ end
54
+ elsif rpc_desc.server_streamer?
55
+ define_method(with) do |request, call, &block|
56
+ call_chain(method_name, request, call, &block)
57
+ end
58
+ else # bidi
59
+ define_method(with) do |requests, call, &block|
60
+ call_chain(method_name, requests, call, &block)
61
+ end
62
+ end
63
+ else
64
+ # fallback to the catch-all
65
+ define_method with do |*args, &block|
66
+ call_chain(method_name, *args, &block)
67
+ end
44
68
  end
69
+
45
70
  alias_method without, method_name
46
71
  alias_method method_name, with
47
72
  @__last_methods_added = nil
@@ -216,23 +241,13 @@ module Gruf
216
241
  # @return [Object] The response object
217
242
  #
218
243
  def call_chain(original_call_sig, req, call, &block)
219
- # this is a workaround until the gRPC core Ruby client implements interceptors
220
- # due to the signatures being different for the different types of requests. After
221
- # interceptors are added to gRPC core, we will need to release gruf 2.0 and redo
222
- # the interceptor signatures for gruf
223
- streamed_request = call.nil?
224
- if streamed_request
225
- call = req
226
- req = nil
227
- end
228
-
229
244
  outer_around_call(original_call_sig, req, call) do
230
245
  begin
231
246
  before_call(original_call_sig, req, call)
232
247
 
233
248
  result = around_call(original_call_sig, req, call) do
234
249
  # send the actual request to gRPC
235
- if streamed_request
250
+ if req.nil?
236
251
  send("#{original_call_sig}_without_intercept", call, &block)
237
252
  else
238
253
  send("#{original_call_sig}_without_intercept", req, call, &block)
@@ -256,6 +271,15 @@ module Gruf
256
271
  fail!(req, call, :internal, :unknown, error_message)
257
272
  end
258
273
 
274
+ ##
275
+ # Return the appropriate RPC descriptor for a given call signature on this service
276
+ #
277
+ # @return [GRPC::RpcDesc]
278
+ #
279
+ def rpc_desc(call_signature)
280
+ self.class.rpc_descs[call_signature.to_s.camelcase.to_sym]
281
+ end
282
+
259
283
  ##
260
284
  # Add a field error to this endpoint
261
285
  #
@@ -15,5 +15,5 @@
15
15
  # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
16
  #
17
17
  module Gruf
18
- VERSION = '1.2.5'.freeze
18
+ VERSION = '1.2.6'.freeze
19
19
  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: 1.2.5
4
+ version: 1.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun McCormick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-30 00:00:00.000000000 Z
11
+ date: 2017-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
159
  version: '0'
160
160
  requirements: []
161
161
  rubyforge_project:
162
- rubygems_version: 2.6.12
162
+ rubygems_version: 2.6.13
163
163
  signing_key:
164
164
  specification_version: 4
165
165
  summary: gRPC Ruby Framework