grpc_kit 0.1.9 → 0.1.10

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
  SHA256:
3
- metadata.gz: c0f50bc31421b7a051756b64bc75d4622e1a66932e919fa2a10d7bc915716969
4
- data.tar.gz: 1e881d306e7c88a6a91da602e2771659fe230c523aedaae96e461621091bec70
3
+ metadata.gz: 8758d861d7f15069510676fb10809b04e88dcce7ad1fba77bbad60aa1140d508
4
+ data.tar.gz: 85c19955c66574e418d190915b9426aca629776a7ea7393ebabe44656c101ab4
5
5
  SHA512:
6
- metadata.gz: 878f6c4a966f9e7af45dc3c57dcb865c93324c21c382439a5b552f67e4dab1ee09f87795af661e39df9cadaf78a20975201fae6af94f2b0b770691369608de55
7
- data.tar.gz: 2e7332f3177f51efdc4f625755dbd92a5f5cdea063635eea1d6a1a75bc499ea87af57633903e12e6aebf5da5ddef028ddecc818bb71623a85b1d995c59e065a6
6
+ metadata.gz: 9642ed431c3fbaa305c9b47f2ddc4ce189c0c2366dbfe80b5b7c913d0da80b5f8ec8240fc981c61646f9b140e72a9e4a7694378809bb2afcb85e69218cd0f612
7
+ data.tar.gz: 6b231bb959a8b2758a9ff48f06749dd4d6ab37369ce9a82f5a5070ed67ea9eba358d1ed4b9f0e27499eb56059119e87eef03f050adf59d6e042d2cc0c506586b
@@ -21,8 +21,9 @@ class LoggingInterceptor < GRPC::ClientInterceptor
21
21
  yield(LoggingStream.new(call))
22
22
  end
23
23
 
24
- def bidi_streamer(**)
25
- yield
24
+ def bidi_streamer(call: nil, method: nil, **)
25
+ GrpcKit.logger.info("Started request method=#{method.name}, service_name=#{method.receiver.class.service_name}")
26
+ yield(LoggingStream.new(call))
26
27
  end
27
28
 
28
29
  class LoggingStream
@@ -31,18 +32,22 @@ class LoggingInterceptor < GRPC::ClientInterceptor
31
32
  end
32
33
 
33
34
  def send_msg(msg, **opts)
34
- GrpcKit.logger.info("logging interceptor send #{msg}")
35
+ GrpcKit.logger.info("logging interceptor send #{msg.inspect}")
35
36
  @stream.send_msg(msg, opts)
36
37
  end
37
38
 
38
39
  def recv(**opt)
39
40
  @stream.recv(opt).tap do |v|
40
- GrpcKit.logger.info("logging interceptor recv #{v}")
41
+ GrpcKit.logger.info("logging interceptor recv #{v.inspect}")
41
42
  end
42
43
  end
43
44
 
44
45
  def close_and_recv
45
46
  @stream.close_and_recv
46
47
  end
48
+
49
+ def close_and_send
50
+ @stream.close_and_send
51
+ end
47
52
  end
48
53
  end
@@ -21,8 +21,9 @@ class LoggingInterceptor < GRPC::ServerInterceptor
21
21
  yield(LoggingStream.new(call))
22
22
  end
23
23
 
24
- def bidi_streamer(**)
25
- yield
24
+ def bidi_streamer(call: nil, method: nil, **)
25
+ GrpcKit.logger.info("Started request method=#{method.name}, service_name=#{method.receiver.class.service_name}")
26
+ yield(LoggingStream.new(call))
26
27
  end
27
28
 
28
29
  class LoggingStream
@@ -31,13 +32,13 @@ class LoggingInterceptor < GRPC::ServerInterceptor
31
32
  end
32
33
 
33
34
  def send_msg(msg, **opt)
34
- GrpcKit.logger.info("logging interceptor send #{msg}")
35
+ GrpcKit.logger.info("logging interceptor send #{msg.inspect}")
35
36
  @stream.send_msg(msg, opt)
36
37
  end
37
38
 
38
39
  def recv(**opt)
39
40
  @stream.recv(**opt).tap do |v|
40
- GrpcKit.logger.info("logging interceptor recv #{v}")
41
+ GrpcKit.logger.info("logging interceptor recv #{v.inspect}")
41
42
  end
42
43
  end
43
44
  end
data/lib/grpc.rb CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  # Compatible file for xx_services_pb.rb and xx_pb.rb which are created by grpc-tools gem
4
4
  require 'grpc_kit'
5
+ require 'grpc_kit/grpc/core'
6
+ require 'grpc_kit/grpc/errors'
5
7
  require 'grpc_kit/grpc/generic_service'
6
8
  require 'grpc_kit/grpc/interceptor'
7
9
  require 'grpc_kit/grpc/logger'
@@ -48,6 +48,8 @@ module GrpcKit
48
48
  return msg
49
49
  end
50
50
  end
51
+
52
+ raise StopIteration
51
53
  rescue GrpcKit::Errors::BadStatus => e
52
54
  @reason = e
53
55
  raise e
@@ -49,7 +49,9 @@ module GrpcKit
49
49
 
50
50
  # @return [Time] deadline of this rpc call
51
51
  def deadline
52
- @deadline ||= @timeout.to_absolute_time
52
+ return @deadline if instance_variable_defined?(:@deadline)
53
+
54
+ @deadline = @timeout && @timeout.to_absolute_time
53
55
  end
54
56
  end
55
57
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'grpc_kit'
4
+
5
+ module GrpcKit
6
+ module GRPC
7
+ module Core
8
+ StatusCodes = GrpcKit::StatusCodes
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'grpc_kit'
4
+ require 'grpc_kit/errors'
5
+
6
+ module GrpcKit
7
+ module GRPC
8
+ include GrpcKit::Errors
9
+ end
10
+ end
@@ -11,8 +11,8 @@ module GrpcKit
11
11
  # @param call [GrpcKit::Calls::Client::BidiStreamer]
12
12
  # @param metadata [Hash<String,String>]
13
13
  def invoke(interceptor, call, metadata)
14
- interceptor.bidi_streamer(requests: nil, call: call, method: call.method, metadata: metadata) do
15
- yield(call, metadata)
14
+ interceptor.bidi_streamer(requests: nil, call: call, method: call.method, metadata: metadata) do |new_call = nil|
15
+ yield(new_call || call, metadata)
16
16
  end
17
17
  end
18
18
  end
@@ -13,8 +13,8 @@ module GrpcKit
13
13
  def invoke(interceptor, call, metadata)
14
14
  # We don't need a `:requests` parameter but,
15
15
  # it shuoldn't remove from paramters due to having a compatibility of grpc gem.
16
- interceptor.client_streamer(requests: nil, call: call, method: call.method, metadata: metadata) do
17
- yield(call, metadata)
16
+ interceptor.client_streamer(requests: nil, call: call, method: call.method, metadata: metadata) do |new_call = nil|
17
+ yield(new_call || call, metadata)
18
18
  end
19
19
  end
20
20
  end
@@ -13,8 +13,8 @@ module GrpcKit
13
13
  def invoke(interceptor, call, metadata)
14
14
  # We don't need a `:request` parameter but,
15
15
  # it shuoldn't remove from paramters due to having a compatibility of grpc gem.
16
- interceptor.server_streamer(request: nil, call: call, method: call.method, metadata: metadata) do
17
- yield(call, metadata)
16
+ interceptor.server_streamer(request: nil, call: call, method: call.method, metadata: metadata) do |new_call = nil|
17
+ yield(new_call || call, metadata)
18
18
  end
19
19
  end
20
20
  end
@@ -8,8 +8,8 @@ module GrpcKit
8
8
  # @param interceptor [GrpcKit::GRPC::ServerInterceptor]
9
9
  # @param call [GrpcKit::Calls::Client::BidiStreamer]
10
10
  def invoke(interceptor, call)
11
- interceptor.bidi_streamer(call: call, method: call.method) do
12
- yield(call)
11
+ interceptor.bidi_streamer(call: call, method: call.method) do |new_call = nil|
12
+ yield(new_call || call)
13
13
  end
14
14
  end
15
15
  end
@@ -8,8 +8,8 @@ module GrpcKit
8
8
  # @param interceptor [GrpcKit::GRPC::ServerInterceptor]
9
9
  # @param call [GrpcKit::Calls::Client::ClientStreamer]
10
10
  def invoke(interceptor, call)
11
- interceptor.client_streamer(call: call, method: call.method) do
12
- yield(call)
11
+ interceptor.client_streamer(call: call, method: call.method) do |new_call = nil|
12
+ yield(new_call || call)
13
13
  end
14
14
  end
15
15
  end
@@ -10,8 +10,8 @@ module GrpcKit
10
10
  def invoke(interceptor, call)
11
11
  # We don't need a `:request` parameter but,
12
12
  # it shuoldn't remove from paramters due to having a compatibility of grpc gem.
13
- interceptor.server_streamer(request: nil, call: call, method: call.method) do
14
- yield(call)
13
+ interceptor.server_streamer(request: nil, call: call, method: call.method) do |new_call = nil|
14
+ yield(new_call || call)
15
15
  end
16
16
  end
17
17
  end
@@ -48,7 +48,7 @@ module GrpcKit
48
48
  path: path,
49
49
  ruby_style_method_name: ruby_style_name,
50
50
  protobuf: server_protobuf,
51
- service_name: @server_name,
51
+ service_name: @service_name,
52
52
  method_name: @name,
53
53
  interceptor: inter,
54
54
  )
@@ -64,7 +64,7 @@ module GrpcKit
64
64
  path: path,
65
65
  ruby_style_method_name: ruby_style_name,
66
66
  protobuf: client_protobuf,
67
- service_name: @server_name,
67
+ service_name: @service_name,
68
68
  method_name: @name,
69
69
  interceptor: inter,
70
70
  )
@@ -35,9 +35,8 @@ module GrpcKit
35
35
  raise ConnectionClosing, "You can't send new request. becuase this connection will shuting down"
36
36
  end
37
37
 
38
- data = GrpcKit::Session::SendBuffer.new
39
- stream_id = submit_request(headers, data).to_i
40
- stream = GrpcKit::Session::Stream.new(stream_id: stream_id, send_data: data)
38
+ stream = GrpcKit::Session::Stream.new(stream_id: 0) # set later
39
+ stream_id = submit_request(headers, stream.pending_send_data).to_i
41
40
  stream.stream_id = stream_id
42
41
  @streams[stream_id] = stream
43
42
  stream
@@ -202,7 +202,7 @@ module GrpcKit
202
202
  raise "#{stream_id} is already existed"
203
203
  end
204
204
 
205
- @streams[stream_id] = GrpcKit::Session::Stream.new(stream_id: stream_id, send_data: GrpcKit::Session::SendBuffer.new)
205
+ @streams[stream_id] = GrpcKit::Session::Stream.new(stream_id: stream_id)
206
206
  end
207
207
 
208
208
  # nghttp2_session_callbacks_set_on_header_callback
@@ -19,14 +19,12 @@ module GrpcKit
19
19
  attr_accessor :inflight, :stream_id
20
20
 
21
21
  # @param stream_id [Integer]
22
- # @param send_data [GrpcKit::Session::SendBuffer]
23
- # @param recv_data [GrpcKit::Session::RecvBuffer]
24
- def initialize(stream_id:, send_data: nil, recv_data: nil)
22
+ def initialize(stream_id:)
25
23
  @stream_id = stream_id
26
24
  @end_read_stream = false
27
25
  @headers = GrpcKit::Session::Headers.new
28
- @pending_send_data = send_data || GrpcKit::Session::SendBuffer.new
29
- @pending_recv_data = recv_data || GrpcKit::Session::RecvBuffer.new
26
+ @pending_send_data = GrpcKit::Session::SendBuffer.new
27
+ @pending_recv_data = GrpcKit::Session::RecvBuffer.new
30
28
 
31
29
  @inflight = false
32
30
  @trailer_data = {}
@@ -143,7 +143,7 @@ module GrpcKit
143
143
 
144
144
  begin
145
145
  @config.protobuf.decode(buf)
146
- rescue ArgumentError => e
146
+ rescue ArgumentError, TypeError => e
147
147
  raise GrpcKit::Errors::Internal, "Error while decoding in Client: #{e}"
148
148
  end
149
149
  end
@@ -33,7 +33,7 @@ module GrpcKit
33
33
  buf =
34
34
  begin
35
35
  protobuf.encode(data)
36
- rescue ArgumentError => e
36
+ rescue ArgumentError, TypeError => e
37
37
  raise GrpcKit::Errors::Internal, "Error while encoding in server: #{e}"
38
38
  end
39
39
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrpcKit
4
- VERSION = '0.1.9'
4
+ VERSION = '0.1.10'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grpc_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - ganmacs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-26 00:00:00.000000000 Z
11
+ date: 2018-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ds9
@@ -182,7 +182,9 @@ files:
182
182
  - lib/grpc_kit/calls/server_server_streamer.rb
183
183
  - lib/grpc_kit/client.rb
184
184
  - lib/grpc_kit/errors.rb
185
+ - lib/grpc_kit/grpc/core.rb
185
186
  - lib/grpc_kit/grpc/dsl.rb
187
+ - lib/grpc_kit/grpc/errors.rb
186
188
  - lib/grpc_kit/grpc/generic_service.rb
187
189
  - lib/grpc_kit/grpc/interceptor.rb
188
190
  - lib/grpc_kit/grpc/logger.rb