griffin 0.1.0 → 0.1.1

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: 40979e4f78d5cd94a55f0f20c2d5fcab6d9d0de4
4
- data.tar.gz: 6ae9e40ac18531f32c2a4a42b984286a4e3d0ac5
2
+ SHA256:
3
+ metadata.gz: 79c985d4054a2fc70cc7f1b55041b5c648fb2edc847540ba610bb79ac0f96cb1
4
+ data.tar.gz: a3089cfff259dc1a8742ea1e776d4577ca06f4e400e3c2ab9417745b893588e5
5
5
  SHA512:
6
- metadata.gz: 31089b1992b4377b7631b76c79a7ed49f74031c75d9692b48faf2970191b81a7099f03cc068f3c4944891d45599971cfd86eb5f90c6e9f55b0d546d77798c232
7
- data.tar.gz: '09cf2ed5e2d5124852cfd3286ec9ad075a113cdc51bef26c57d33324e9cc806a29a777433bfe74e22d96e8cf98dd340c8f15bdb0c53f71ddf3de71defc3ab999'
6
+ metadata.gz: 73fa55a2b5fb9dbe1d00829e5add7769cb76ffb03c6d03600c50c9a3d2c2c8465442d80e2f2ed652135cc0a8dad02417e42c6fb1cab0c4d90b98baee9b3261ff
7
+ data.tar.gz: 101657f06a41028df869bf0e1aa3e33dd88ced2385554daf82e9c01a7d39479044930026456d9257accb36671393c4d6d7eb4fb8c5ede9394f6acb1d72983ba7
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,86 @@
1
+ AllCops:
2
+ Exclude:
3
+ - '**/**/*_pb.rb' # auto-generated
4
+ - "vendor/**/*"
5
+ DisplayCopNames: true
6
+ TargetRubyVersion: 2.5
7
+
8
+ Style/AndOr:
9
+ EnforcedStyle: conditionals
10
+
11
+ Style/AsciiComments:
12
+ Enabled: false
13
+
14
+ Style/Documentation:
15
+ Enabled: false
16
+
17
+ Style/DoubleNegation:
18
+ Enabled: false
19
+
20
+ Style/EmptyElse:
21
+ EnforcedStyle: empty
22
+
23
+ Style/FormatString:
24
+ EnforcedStyle: percent
25
+
26
+ Style/IfUnlessModifier:
27
+ Enabled: false
28
+
29
+ Style/TrailingCommaInHashLiteral:
30
+ EnforcedStyleForMultiline: comma
31
+
32
+ Style/TrailingCommaInArguments:
33
+ EnforcedStyleForMultiline: comma
34
+
35
+ Style/SafeNavigation:
36
+ Enabled: false
37
+
38
+ Naming/PredicateName:
39
+ NamePrefixBlacklist:
40
+ - "is_"
41
+ - "have_"
42
+ NamePrefix:
43
+ - "is_"
44
+ - "have_"
45
+
46
+ Style/SignalException:
47
+ EnforcedStyle: only_raise
48
+
49
+ Style/SingleLineBlockParams:
50
+ Enabled: false
51
+
52
+ Style/NumericLiterals:
53
+ Enabled: false
54
+
55
+ Style/GuardClause:
56
+ Enabled: false
57
+
58
+ Style/NumericPredicate:
59
+ Enabled: false
60
+
61
+ Metrics/ParameterLists:
62
+ CountKeywordArgs: false
63
+
64
+ Lint/UnderscorePrefixedVariableName:
65
+ Enabled: false
66
+
67
+ Metrics/AbcSize:
68
+ Max: 50
69
+
70
+ Metrics/CyclomaticComplexity:
71
+ Max: 10
72
+
73
+ Metrics/LineLength:
74
+ Max: 160
75
+
76
+ Metrics/MethodLength:
77
+ Max: 40
78
+
79
+ Metrics/PerceivedComplexity:
80
+ Max: 20
81
+
82
+ Metrics/ClassLength:
83
+ Max: 200
84
+
85
+ Metrics/BlockLength:
86
+ Max: 40
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in griffin.gemspec
6
8
  gemspec
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 TODO: Write your name
3
+ Copyright (c) 2018 TODO: ganmacs
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # Griffin
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/griffin`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Gem Version](https://badge.fury.io/rb/griffin.svg)](https://badge.fury.io/rb/griffin)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+
6
+ __UNDER DEVELOPMENT__
7
+
8
+ Griffin is [gRPC](https://grpc.io/) server which supports multi process by using [serverengine](https://github.com/treasure-data/serverengine).
9
+ Griffin also supports building gRPC client.
6
10
 
7
11
  ## Installation
8
12
 
@@ -14,25 +18,54 @@ gem 'griffin'
14
18
 
15
19
  And then execute:
16
20
 
17
- $ bundle
21
+ ```
22
+ $ bundle
23
+ ```
18
24
 
19
25
  Or install it yourself as:
20
26
 
21
- $ gem install griffin
27
+ ```
28
+ gem install griffin
29
+ ```
22
30
 
23
31
  ## Usage
24
32
 
25
- TODO: Write usage instructions here
33
+ #### Server
34
+
35
+ ```ruby
36
+ class GreeterServer < Helloworld::Greeter::Service
37
+ def say_hello(hello_req, _unused_call)
38
+ Helloworld::HelloReply.new(message: "Hello #{hello_req.name}")
39
+ end
40
+ end
41
+
42
+ Griffin::Server.configure do |c|
43
+ c.bind '127.0.0.1'
44
+
45
+ c.port 50051
46
+
47
+ c.services GreeterServer.new
48
+
49
+ c.worker 2 # A number of worker process
50
+ end
51
+
52
+ Griffin::Server.run
53
+
54
+ ```
26
55
 
27
56
  ## Development
28
57
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+ ```
59
+ bundle install
60
+ ```
61
+
62
+ ## Requirements
30
63
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+ * [nghttp2](https://nghttp2.org/)
32
65
 
33
66
  ## Contributing
34
67
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/griffin. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ganmacs/griffin.
36
69
 
37
70
  ## License
38
71
 
@@ -40,4 +73,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
40
73
 
41
74
  ## Code of Conduct
42
75
 
43
- Everyone interacting in the Griffin project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/griffin/blob/master/CODE_OF_CONDUCT.md).
76
+ TODO
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "griffin"
4
+ require 'bundler/setup'
5
+ require 'griffin'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "griffin"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -0,0 +1,37 @@
1
+ // Copyright 2015 gRPC authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ syntax = "proto3";
16
+
17
+ option java_multiple_files = true;
18
+ option java_package = "io.grpc.examples.helloworld";
19
+ option java_outer_classname = "HelloWorldProto";
20
+
21
+ package helloworld;
22
+
23
+ // The greeting service definition.
24
+ service Greeter {
25
+ // Sends a greeting
26
+ rpc SayHello (HelloRequest) returns (HelloReply) {}
27
+ }
28
+
29
+ // The request message containing the user's name.
30
+ message HelloRequest {
31
+ string name = 1;
32
+ }
33
+
34
+ // The response message containing the greetings
35
+ message HelloReply {
36
+ string message = 1;
37
+ }
@@ -0,0 +1,18 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: helloworld.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_message "helloworld.HelloRequest" do
8
+ optional :name, :string, 1
9
+ end
10
+ add_message "helloworld.HelloReply" do
11
+ optional :message, :string, 1
12
+ end
13
+ end
14
+
15
+ module Helloworld
16
+ HelloRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("helloworld.HelloRequest").msgclass
17
+ HelloReply = Google::Protobuf::DescriptorPool.generated_pool.lookup("helloworld.HelloReply").msgclass
18
+ end
@@ -0,0 +1,22 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: helloworld.proto for package 'helloworld'
3
+
4
+ require 'grpc'
5
+ require 'helloworld_pb'
6
+
7
+ module Helloworld
8
+ module Greeter
9
+ class Service
10
+
11
+ include GRPC::GenericService
12
+
13
+ self.marshal_class_method = :encode
14
+ self.unmarshal_class_method = :decode
15
+ self.service_name = 'helloworld.Greeter'
16
+
17
+ rpc :SayHello, HelloRequest, HelloReply
18
+ end
19
+
20
+ Stub = Service.rpc_stub_class
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: false
2
+
3
+ $LOAD_PATH.unshift File.expand_path('./examples/helloworld')
4
+
5
+ require 'griffin'
6
+ require 'socket'
7
+ require 'pry'
8
+ require 'helloworld_services_pb'
9
+
10
+ stub = Helloworld::Greeter::Stub.new('localhost', 50051)
11
+ message = stub.say_hello(Helloworld::HelloRequest.new(name: 'ganmacs')).message
12
+ p message
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path('./examples/helloworld')
4
+
5
+ require 'griffin'
6
+ require 'helloworld_services_pb'
7
+
8
+ class GreeterServer < Helloworld::Greeter::Service
9
+ def say_hello(hello_req, _unused_call)
10
+ Helloworld::HelloReply.new(message: "Hello #{hello_req.name}")
11
+ end
12
+ end
13
+
14
+ Griffin::Server.configure do |c|
15
+ c.bind '127.0.0.1'
16
+
17
+ c.port 50051
18
+
19
+ c.services GreeterServer.new
20
+ end
21
+
22
+ Griffin::Server.run
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'grpc_kit'
4
+
5
+ class LoggingInterceptor < GRPC::ClientInterceptor
6
+ def request_response(request: nil, method: nil, **)
7
+ now = Time.now.to_i
8
+ GrpcKit.logger.info("Started request #{request}, method=#{method.name}, service_name=#{method.receiver.class.service_name}")
9
+ yield.tap do
10
+ GrpcKit.logger.info("Elapsed Time: #{Time.now.to_i - now}")
11
+ end
12
+ end
13
+
14
+ def client_streamer(call: nil, method: nil, **)
15
+ GrpcKit.logger.info("Started request method=#{method.name}, service_name=#{method.receiver.class.service_name}")
16
+ yield(LoggingStream.new(call))
17
+ end
18
+
19
+ def server_streamer(call: nil, method: nil, **)
20
+ GrpcKit.logger.info("Started request method=#{method.name}, service_name=#{method.receiver.class.service_name}")
21
+ yield(LoggingStream.new(call))
22
+ end
23
+
24
+ def bidi_streamer(**)
25
+ yield
26
+ end
27
+
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)
36
+ end
37
+
38
+ def recv(**opt)
39
+ @stream.recv(opt).tap do |v|
40
+ GrpcKit.logger.info("logging interceptor recv #{v}")
41
+ end
42
+ end
43
+
44
+ def close_and_recv
45
+ @stream.close_and_recv
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'grpc_kit'
4
+
5
+ class LoggingInterceptor < GRPC::ServerInterceptor
6
+ def request_response(request: nil, call: nil, method: nil)
7
+ now = Time.now.to_i
8
+ GrpcKit.logger.info("Started request #{request}, method=#{method.name}, service_name=#{method.receiver.class.service_name}")
9
+ yield(request, call).tap do
10
+ GrpcKit.logger.info("Elapsed Time: #{Time.now.to_i - now}")
11
+ end
12
+ end
13
+
14
+ def client_streamer(call: nil, method: nil)
15
+ GrpcKit.logger.info("Started request method=#{method.name}, service_name=#{method.receiver.class.service_name}")
16
+ yield(LoggingStream.new(call))
17
+ end
18
+
19
+ def server_streamer(call: nil, method: nil, **)
20
+ GrpcKit.logger.info("Started request method=#{method.name}, service_name=#{method.receiver.class.service_name}")
21
+ yield(LoggingStream.new(call))
22
+ end
23
+
24
+ def bidi_streamer(**)
25
+ yield
26
+ end
27
+
28
+ class LoggingStream
29
+ def initialize(stream)
30
+ @stream = stream
31
+ end
32
+
33
+ def send_msg(msg, **opt)
34
+ GrpcKit.logger.info("logging interceptor send #{msg}")
35
+ @stream.send_msg(msg, opt)
36
+ end
37
+
38
+ def recv(**opt)
39
+ @stream.recv(**opt).tap do |v|
40
+ GrpcKit.logger.info("logging interceptor recv #{v}")
41
+ end
42
+ end
43
+ end
44
+ end