griffin 0.1.4 → 0.1.5

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: 307fd7dcba526d6bb562bf97d4d7c31c0f82d1fdfb488de21a5fb1040cc6506e
4
- data.tar.gz: 01a0b9ddfcd3486a9c1b378c11b22dc35856fd264f283c68e19f74973fe6f588
3
+ metadata.gz: bde96b38724aa97b682bfc64f06b7aafd3839191c879e3c4cd99f818b411f98a
4
+ data.tar.gz: 7e6906a7bffae9171156ec71a68bef87f38cc8b5b668d7ea886953d83cfdbeff
5
5
  SHA512:
6
- metadata.gz: 8780b448b45fb336c4bd7196e23e3901a64822fd0ed9661d8b2e59fb4d437feb2527cc1388b7162a2f927f37f229e36d6c5476bf2c5af17c407a38b298ab38b9
7
- data.tar.gz: 6026c11481574d680a0b79295109da1405656aecd63424c3f228bbc765144d1019da666d3684d2efd8e1319c578df043607efff8d44e8a933f6a3b910a33f62f
6
+ metadata.gz: def92a8064a0141d4b4b2ad73429d81abcab11c6ba5597789b6a8a955f426e2a8c3699edb49042175ac7c904364afec7e6f9e6784f20a107e7f10ac2787af4ed
7
+ data.tar.gz: 855a0900def7e9630017cd695e5f120a0e080a89e36199a426ef9060bd3692a28121f4b9b6155a0df2398a87e3d430e2768d373553fe8b5edcdaab6160bc065e
data/.rubocop.yml CHANGED
@@ -29,12 +29,18 @@ Style/IfUnlessModifier:
29
29
  Style/TrailingCommaInHashLiteral:
30
30
  EnforcedStyleForMultiline: comma
31
31
 
32
+ Style/TrailingCommaInArrayLiteral:
33
+ EnforcedStyleForMultiline: comma
34
+
32
35
  Style/TrailingCommaInArguments:
33
36
  EnforcedStyleForMultiline: comma
34
37
 
35
38
  Style/SafeNavigation:
36
39
  Enabled: false
37
40
 
41
+ Style/WhileUntilModifier:
42
+ Enabled: false
43
+
38
44
  Naming/PredicateName:
39
45
  NamePrefixBlacklist:
40
46
  - "is_"
data/README.md CHANGED
@@ -59,10 +59,6 @@ Griffin::Server.run
59
59
  bundle install
60
60
  ```
61
61
 
62
- ## Requirements
63
-
64
- * [nghttp2](https://nghttp2.org/)
65
-
66
62
  ## Contributing
67
63
 
68
64
  Bug reports and pull requests are welcome on GitHub at https://github.com/ganmacs/griffin.
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'grpc_kit'
4
+ require 'forwardable'
5
+
6
+ class CallStream < GrpcKit::Call
7
+ include Enumerable
8
+ extend Forwardable
9
+ delegate %i[send_msg recv] => :@inner
10
+
11
+ # @params call [GrpcKit::Call]
12
+ def initialize(inner)
13
+ @inner = inner
14
+ end
15
+
16
+ def each
17
+ loop { yield(recv) }
18
+ end
19
+
20
+ def method_missing(name, *args, &block)
21
+ @inner.public_send(name, *args, &block)
22
+ end
23
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'grpc_kit'
4
+ require_relative 'call_stream'
4
5
 
5
6
  class LoggingInterceptor < GRPC::ClientInterceptor
6
7
  def request_response(request: nil, method: nil, **)
@@ -21,28 +22,21 @@ class LoggingInterceptor < GRPC::ClientInterceptor
21
22
  yield(LoggingStream.new(call))
22
23
  end
23
24
 
24
- def bidi_streamer(**)
25
- yield
25
+ def bidi_streamer(call: nil, method: nil, **)
26
+ GrpcKit.logger.info("Started request method=#{method.name}, service_name=#{method.receiver.class.service_name}")
27
+ yield(LoggingStream.new(call))
26
28
  end
27
29
 
28
- class LoggingStream
29
- def initialize(stream)
30
- @stream = stream
31
- end
32
-
33
- def send_msg(msg, **opts)
34
- GrpcKit.logger.info("logging interceptor send #{msg}")
35
- @stream.send_msg(msg, opts)
30
+ class LoggingStream < CallStream
31
+ def send_msg(msg)
32
+ GrpcKit.logger.info("logging interceptor send #{msg.inspect}")
33
+ super
36
34
  end
37
35
 
38
- def recv(**opt)
39
- @stream.recv(opt).tap do |v|
40
- GrpcKit.logger.info("logging interceptor recv #{v}")
36
+ def recv
37
+ super.tap do |v|
38
+ GrpcKit.logger.info("logging interceptor recv #{v.inspect}")
41
39
  end
42
40
  end
43
-
44
- def close_and_recv
45
- @stream.close_and_recv
46
- end
47
41
  end
48
42
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'grpc_kit'
4
+ require_relative 'call_stream'
4
5
 
5
6
  class LoggingInterceptor < GRPC::ServerInterceptor
6
7
  def request_response(request: nil, call: nil, method: nil)
@@ -26,18 +27,14 @@ class LoggingInterceptor < GRPC::ServerInterceptor
26
27
  yield(LoggingStream.new(call))
27
28
  end
28
29
 
29
- class LoggingStream
30
- def initialize(stream)
31
- @stream = stream
32
- end
33
-
34
- def send_msg(msg, **opt)
30
+ class LoggingStream < CallStream
31
+ def send_msg(msg)
35
32
  GrpcKit.logger.info("logging interceptor send #{msg.inspect}")
36
- @stream.send_msg(msg, opt)
33
+ super
37
34
  end
38
35
 
39
- def recv(**opt)
40
- @stream.recv(**opt).tap do |v|
36
+ def recv
37
+ super.tap do |v|
41
38
  GrpcKit.logger.info("logging interceptor recv #{v.inspect}")
42
39
  end
43
40
  end
@@ -14,8 +14,8 @@ PORT = 50051
14
14
  def get_feature(stub)
15
15
  GRPC.logger.info('===== get_feature =====')
16
16
  points = [
17
- Routeguide::Point.new(latitude: 409_146_138, longitude: -746_188_906),
18
- Routeguide::Point.new(latitude: 0, longitude: 0)
17
+ Routeguide::Point.new(latitude: 409_146_138, longitude: -746_188_906),
18
+ Routeguide::Point.new(latitude: 0, longitude: 0),
19
19
  ]
20
20
 
21
21
  points.each do |pt|
@@ -36,9 +36,7 @@ def list_features(stub)
36
36
  )
37
37
 
38
38
  stream = stub.list_features(rect)
39
-
40
- loop do
41
- r = stream.recv
39
+ stream.each do |r|
42
40
  GRPC.logger.info("Found #{r.name} at #{r.location.inspect}")
43
41
  end
44
42
  end
@@ -55,13 +53,13 @@ def record_route(stub, size)
55
53
  size.times do
56
54
  location = features.sample['location']
57
55
  point = Routeguide::Point.new(latitude: location['latitude'], longitude: location['longitude'])
58
- puts "Next point is #{point.inspect}"
56
+ GRPC.logger.info("Next point is #{point.inspect}")
59
57
  stream.send_msg(point)
60
58
  sleep(rand(0..1))
61
59
  end
62
60
 
63
- resp = stream.close_and_recv
64
- puts "summary: #{resp[0].inspect}"
61
+ resp = stream.recv
62
+ GRPC.logger.info("summary: #{resp.inspect}")
65
63
  end
66
64
 
67
65
  ROUTE_CHAT_NOTES = [
@@ -79,9 +77,8 @@ def route_chat(stub)
79
77
  call = stub.route_chat({})
80
78
 
81
79
  t = Thread.new do
82
- loop do
83
- rn = call.recv
84
- GRPC.logger.info("Got message #{rn.message} at point point(#{rn.location.latitude}, #{rn.location.longitude})")
80
+ call.each do |rn|
81
+ GRPC.logger.info("Got message #{rn.message} at point (#{rn.location.latitude}, #{rn.location.longitude})")
85
82
  end
86
83
  end
87
84
 
@@ -20,6 +20,7 @@ class Server < Routeguide::RouteGuide::Service
20
20
  end
21
21
 
22
22
  def get_feature(point, ctx)
23
+ GRPC.logger.info('===== get_feature =====')
23
24
  name = @features.fetch({ 'longitude' => point.longitude, 'latitude' => point.latitude }, '')
24
25
  GRPC.logger.info("Point longitude=#{point.longitude}, latitude=#{point.latitude}, metadata=#{ctx.metadata}")
25
26
  Routeguide::Feature.new(location: point, name: name)
@@ -48,8 +49,7 @@ class Server < Routeguide::RouteGuide::Service
48
49
  start_at = Time.now.to_i
49
50
  last = nil
50
51
 
51
- loop do
52
- point = stream.recv # XXX: raise StopIteration
52
+ stream.each do |point|
53
53
  GRPC.logger.info(point)
54
54
 
55
55
  count += 1
@@ -71,8 +71,8 @@ class Server < Routeguide::RouteGuide::Service
71
71
  end
72
72
 
73
73
  def route_chat(call)
74
- loop do
75
- rn = call.recv
74
+ GRPC.logger.info('===== record_chat =====')
75
+ call.each do |rn|
76
76
  GRPC.logger.info("route_note location=#{rn.location.inspect}, message=#{rn.message}")
77
77
  key = "#{rn.location.latitude} #{rn.location.longitude}"
78
78
  saved_msgs = @route_notes[key]
@@ -121,6 +121,11 @@ Griffin::Server.configure do |c|
121
121
 
122
122
  c.services Server.new
123
123
 
124
+ if ENV['GRPC_INTERCEPTOR']
125
+ require_relative 'interceptors/server_logging_interceptor'
126
+ c.interceptors [LoggingInterceptor.new]
127
+ end
128
+
124
129
  c.workers 2
125
130
  end
126
131
 
data/griffin.gemspec CHANGED
@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'rubocop'
30
30
 
31
31
  spec.add_dependency 'connection_pool', '~> 2.2.2'
32
- spec.add_dependency 'grpc_kit', '~> 0.1.12'
32
+ spec.add_dependency 'grpc_kit', '>= 0.2.0'
33
33
  spec.add_dependency 'serverengine', '~> 2.0.7'
34
34
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Griffin
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  end
@@ -14,7 +14,6 @@
14
14
 
15
15
  require 'grpc'
16
16
  require 'grpc/health/v1/health_services_pb'
17
- require 'thread'
18
17
 
19
18
  module Grpc
20
19
  # Health contains classes and modules that support providing a health check
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: griffin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
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-29 00:00:00.000000000 Z
11
+ date: 2018-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,16 +98,16 @@ dependencies:
98
98
  name: grpc_kit
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: 0.1.12
103
+ version: 0.2.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: 0.1.12
110
+ version: 0.2.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: serverengine
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -145,6 +145,7 @@ files:
145
145
  - examples/helloworld/helloworld_services_pb.rb
146
146
  - examples/helloworld_client.rb
147
147
  - examples/helloworld_server.rb
148
+ - examples/interceptors/call_stream.rb
148
149
  - examples/interceptors/client_logging_interceptor.rb
149
150
  - examples/interceptors/server_logging_interceptor.rb
150
151
  - examples/routeguide/routeguide.json