protobuf 3.3.6 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +48 -0
- data/.rubocop_todo.yml +79 -0
- data/.travis.yml +12 -4
- data/Rakefile +14 -11
- data/bin/protoc-gen-ruby +0 -1
- data/bin/rpc_server +1 -0
- data/install-protobuf.sh +8 -0
- data/lib/protobuf.rb +30 -24
- data/lib/protobuf/cli.rb +35 -35
- data/lib/protobuf/code_generator.rb +11 -8
- data/lib/protobuf/decoder.rb +4 -5
- data/lib/protobuf/deprecation.rb +20 -0
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +2 -0
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +2 -0
- data/lib/protobuf/encoder.rb +9 -4
- data/lib/protobuf/enum.rb +38 -54
- data/lib/protobuf/field.rb +2 -2
- data/lib/protobuf/field/base_field.rb +28 -32
- data/lib/protobuf/field/bool_field.rb +4 -4
- data/lib/protobuf/field/bytes_field.rb +5 -4
- data/lib/protobuf/field/double_field.rb +0 -1
- data/lib/protobuf/field/enum_field.rb +4 -7
- data/lib/protobuf/field/field_array.rb +3 -4
- data/lib/protobuf/field/fixed32_field.rb +1 -1
- data/lib/protobuf/field/fixed64_field.rb +0 -1
- data/lib/protobuf/field/float_field.rb +0 -1
- data/lib/protobuf/field/int32_field.rb +0 -1
- data/lib/protobuf/field/int64_field.rb +0 -1
- data/lib/protobuf/field/integer_field.rb +0 -1
- data/lib/protobuf/field/message_field.rb +2 -3
- data/lib/protobuf/field/sfixed32_field.rb +0 -1
- data/lib/protobuf/field/sfixed64_field.rb +0 -1
- data/lib/protobuf/field/signed_integer_field.rb +0 -1
- data/lib/protobuf/field/sint32_field.rb +0 -1
- data/lib/protobuf/field/sint64_field.rb +0 -1
- data/lib/protobuf/field/string_field.rb +0 -1
- data/lib/protobuf/field/uint32_field.rb +0 -1
- data/lib/protobuf/field/uint64_field.rb +0 -1
- data/lib/protobuf/field/varint_field.rb +0 -1
- data/lib/protobuf/generators/base.rb +1 -2
- data/lib/protobuf/generators/enum_generator.rb +1 -2
- data/lib/protobuf/generators/extension_generator.rb +1 -2
- data/lib/protobuf/generators/field_generator.rb +4 -5
- data/lib/protobuf/generators/file_generator.rb +22 -27
- data/lib/protobuf/generators/group_generator.rb +15 -16
- data/lib/protobuf/generators/message_generator.rb +13 -14
- data/lib/protobuf/generators/printable.rb +9 -10
- data/lib/protobuf/generators/service_generator.rb +1 -2
- data/lib/protobuf/lifecycle.rb +20 -33
- data/lib/protobuf/logging.rb +4 -6
- data/lib/protobuf/message.rb +22 -16
- data/lib/protobuf/message/fields.rb +14 -17
- data/lib/protobuf/message/serialization.rb +6 -5
- data/lib/protobuf/rpc/buffer.rb +10 -12
- data/lib/protobuf/rpc/client.rb +12 -12
- data/lib/protobuf/rpc/connectors/base.rb +4 -3
- data/lib/protobuf/rpc/connectors/common.rb +15 -17
- data/lib/protobuf/rpc/connectors/socket.rb +2 -2
- data/lib/protobuf/rpc/connectors/zmq.rb +118 -108
- data/lib/protobuf/rpc/dynamic_discovery.pb.rb +2 -0
- data/lib/protobuf/rpc/env.rb +12 -12
- data/lib/protobuf/rpc/error.rb +1 -1
- data/lib/protobuf/rpc/error/client_error.rb +4 -4
- data/lib/protobuf/rpc/error/server_error.rb +6 -6
- data/lib/protobuf/rpc/middleware/exception_handler.rb +1 -1
- data/lib/protobuf/rpc/middleware/logger.rb +3 -3
- data/lib/protobuf/rpc/middleware/request_decoder.rb +5 -5
- data/lib/protobuf/rpc/middleware/response_encoder.rb +3 -3
- data/lib/protobuf/rpc/rpc.pb.rb +2 -0
- data/lib/protobuf/rpc/servers/socket/server.rb +75 -65
- data/lib/protobuf/rpc/servers/socket/worker.rb +2 -2
- data/lib/protobuf/rpc/servers/socket_runner.rb +12 -6
- data/lib/protobuf/rpc/servers/zmq/broker.rb +10 -6
- data/lib/protobuf/rpc/servers/zmq/server.rb +20 -26
- data/lib/protobuf/rpc/servers/zmq/util.rb +7 -7
- data/lib/protobuf/rpc/servers/zmq/worker.rb +5 -7
- data/lib/protobuf/rpc/servers/zmq_runner.rb +14 -3
- data/lib/protobuf/rpc/service.rb +15 -15
- data/lib/protobuf/rpc/service_directory.rb +7 -11
- data/lib/protobuf/rpc/service_dispatcher.rb +3 -3
- data/lib/protobuf/rpc/service_filters.rb +27 -28
- data/lib/protobuf/rpc/stat.rb +4 -7
- data/lib/protobuf/socket.rb +0 -1
- data/lib/protobuf/tasks/compile.rake +2 -2
- data/lib/protobuf/version.rb +1 -1
- data/protobuf.gemspec +20 -4
- data/spec/benchmark/tasks.rb +49 -23
- data/spec/bin/protoc-gen-ruby_spec.rb +11 -6
- data/spec/encoding/all_types_spec.rb +91 -77
- data/spec/encoding/extreme_values_spec.rb +0 -0
- data/spec/functional/socket_server_spec.rb +9 -10
- data/spec/functional/zmq_server_spec.rb +21 -19
- data/spec/lib/protobuf/cli_spec.rb +20 -20
- data/spec/lib/protobuf/code_generator_spec.rb +6 -6
- data/spec/lib/protobuf/enum_spec.rb +57 -31
- data/spec/lib/protobuf/field/float_field_spec.rb +2 -2
- data/spec/lib/protobuf/field/int32_field_spec.rb +1 -1
- data/spec/lib/protobuf/field/string_field_spec.rb +7 -8
- data/spec/lib/protobuf/field_spec.rb +3 -6
- data/spec/lib/protobuf/generators/base_spec.rb +6 -6
- data/spec/lib/protobuf/generators/enum_generator_spec.rb +22 -17
- data/spec/lib/protobuf/generators/extension_generator_spec.rb +8 -9
- data/spec/lib/protobuf/generators/field_generator_spec.rb +14 -11
- data/spec/lib/protobuf/generators/file_generator_spec.rb +7 -4
- data/spec/lib/protobuf/generators/service_generator_spec.rb +14 -11
- data/spec/lib/protobuf/lifecycle_spec.rb +9 -4
- data/spec/lib/protobuf/message_spec.rb +63 -35
- data/spec/lib/protobuf/optionable_spec.rb +3 -3
- data/spec/lib/protobuf/rpc/client_spec.rb +2 -2
- data/spec/lib/protobuf/rpc/connector_spec.rb +1 -1
- data/spec/lib/protobuf/rpc/connectors/base_spec.rb +6 -6
- data/spec/lib/protobuf/rpc/connectors/common_spec.rb +26 -18
- data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +4 -4
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +11 -9
- data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +2 -2
- data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +7 -7
- data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +14 -14
- data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +5 -5
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +1 -1
- data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +9 -7
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +9 -9
- data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +2 -2
- data/spec/lib/protobuf/rpc/service_directory_spec.rb +24 -23
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +4 -4
- data/spec/lib/protobuf/rpc/service_filters_spec.rb +84 -51
- data/spec/lib/protobuf/rpc/service_spec.rb +15 -14
- data/spec/lib/protobuf/rpc/stat_spec.rb +1 -1
- data/spec/lib/protobuf_spec.rb +9 -9
- data/spec/spec_helper.rb +7 -19
- data/spec/support/server.rb +29 -59
- data/spec/support/test/defaults.pb.rb +2 -0
- data/spec/support/test/enum.pb.rb +2 -0
- data/spec/support/test/extended.pb.rb +2 -0
- data/spec/support/test/google_unittest_import.pb.rb +2 -0
- data/spec/support/test/google_unittest_import_public.pb.rb +2 -0
- data/spec/support/test/multi_field_extensions.pb.rb +2 -0
- data/spec/support/test/resource.pb.rb +2 -0
- data/spec/support/test/resource_service.rb +17 -20
- metadata +153 -112
- data/lib/protobuf/deprecator.rb +0 -42
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8975f51cd8e6d910cbe547b32bc5107fa4d197a5
|
4
|
+
data.tar.gz: 3f39633e344de3b196a11b8182e85884ddb678e1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8b7ca982042d842556d2f239cd0f5a70c33905efa33b1269baf8c29f6db2cafc64ee9efdc114dc9b702a07d25c13a8ded348552f94e259483f36f4ca4253e889
|
7
|
+
data.tar.gz: dc741258194bc09864a45ff2d6824544095f60c7658fefeb4e062d2ccdfb9684bd511254c351c0e8e8574d30f75877bff1a4c7ad1f4ab569d5baae0857ebceb8
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
Lint/EndAlignment:
|
4
|
+
AlignWith: variable
|
5
|
+
|
6
|
+
Lint/Loop:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Style/CaseIndentation:
|
10
|
+
IndentWhenRelativeTo: end
|
11
|
+
|
12
|
+
Style/ClassAndModuleChildren:
|
13
|
+
Exclude:
|
14
|
+
- '**/*.pb.rb'
|
15
|
+
|
16
|
+
Style/EmptyLineBetweenDefs:
|
17
|
+
AllowAdjacentOneLineDefs: true
|
18
|
+
|
19
|
+
Style/EmptyLines:
|
20
|
+
Exclude:
|
21
|
+
- '**/*.pb.rb'
|
22
|
+
|
23
|
+
Style/FileName:
|
24
|
+
Exclude:
|
25
|
+
- '**/protoc-gen-ruby*'
|
26
|
+
|
27
|
+
Style/GuardClause:
|
28
|
+
MinBodyLength: 4
|
29
|
+
|
30
|
+
Style/HashSyntax:
|
31
|
+
EnforcedStyle: hash_rockets
|
32
|
+
|
33
|
+
Style/IndentHash:
|
34
|
+
EnforcedStyle: consistent
|
35
|
+
|
36
|
+
Style/Semicolon:
|
37
|
+
AllowAsExpressionSeparator: true
|
38
|
+
|
39
|
+
Style/TrailingBlankLines:
|
40
|
+
Exclude:
|
41
|
+
- '**/*.pb.rb'
|
42
|
+
|
43
|
+
Style/TrailingComma:
|
44
|
+
EnforcedStyleForMultiline: comma
|
45
|
+
|
46
|
+
Style/TrivialAccessors:
|
47
|
+
AllowDSLWriters: true
|
48
|
+
AllowPredicates: true
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2014-11-24 09:44:26 -0800 using RuboCop version 0.27.1.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 28
|
9
|
+
Metrics/AbcSize:
|
10
|
+
Max: 59
|
11
|
+
|
12
|
+
# Offense count: 3
|
13
|
+
Metrics/BlockNesting:
|
14
|
+
Max: 5
|
15
|
+
|
16
|
+
# Offense count: 9
|
17
|
+
# Configuration parameters: CountComments.
|
18
|
+
Metrics/ClassLength:
|
19
|
+
Max: 233
|
20
|
+
|
21
|
+
# Offense count: 3
|
22
|
+
Metrics/CyclomaticComplexity:
|
23
|
+
Max: 11
|
24
|
+
|
25
|
+
# Offense count: 508
|
26
|
+
# Configuration parameters: AllowURI, URISchemes.
|
27
|
+
Metrics/LineLength:
|
28
|
+
Max: 196
|
29
|
+
|
30
|
+
# Offense count: 48
|
31
|
+
# Configuration parameters: CountComments.
|
32
|
+
Metrics/MethodLength:
|
33
|
+
Max: 45
|
34
|
+
|
35
|
+
# Offense count: 2
|
36
|
+
# Configuration parameters: CountKeywordArgs.
|
37
|
+
Metrics/ParameterLists:
|
38
|
+
Max: 6
|
39
|
+
|
40
|
+
# Offense count: 2
|
41
|
+
Metrics/PerceivedComplexity:
|
42
|
+
Max: 12
|
43
|
+
|
44
|
+
# Offense count: 216
|
45
|
+
Style/Documentation:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
# Offense count: 15
|
49
|
+
Style/DoubleNegation:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
# Offense count: 100
|
53
|
+
# Cop supports --auto-correct.
|
54
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
55
|
+
Style/EmptyLinesAroundClassBody:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
# Offense count: 66
|
59
|
+
# Cop supports --auto-correct.
|
60
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
61
|
+
Style/EmptyLinesAroundModuleBody:
|
62
|
+
Enabled: false
|
63
|
+
|
64
|
+
# Offense count: 53
|
65
|
+
# Cop supports --auto-correct.
|
66
|
+
Style/NumericLiterals:
|
67
|
+
MinDigits: 21
|
68
|
+
|
69
|
+
# Offense count: 464
|
70
|
+
# Cop supports --auto-correct.
|
71
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
72
|
+
Style/StringLiterals:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
# Offense count: 4
|
76
|
+
# Cop supports --auto-correct.
|
77
|
+
# Configuration parameters: WordRegex.
|
78
|
+
Style/WordArray:
|
79
|
+
MinSize: 2
|
data/.travis.yml
CHANGED
@@ -1,9 +1,17 @@
|
|
1
|
+
before_install:
|
2
|
+
- sudo apt-get update -qq
|
3
|
+
- sudo apt-get install -y libzmq3-dev
|
4
|
+
- sudo ./install-protobuf.sh
|
1
5
|
language: ruby
|
2
6
|
rvm:
|
3
|
-
-
|
4
|
-
-
|
5
|
-
-
|
6
|
-
|
7
|
+
- 1.9.3
|
8
|
+
- 2.0.0
|
9
|
+
- 2.1
|
10
|
+
- jruby
|
11
|
+
- rbx-2
|
12
|
+
matrix:
|
13
|
+
allow_failures:
|
14
|
+
- rvm: rbx-2
|
7
15
|
notifications:
|
8
16
|
webhooks:
|
9
17
|
urls:
|
data/Rakefile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
$LOAD_PATH << ::File.expand_path('../', __FILE__)
|
2
|
+
$LOAD_PATH << ::File.expand_path('../spec', __FILE__)
|
3
3
|
|
4
4
|
require 'fileutils'
|
5
5
|
require 'rubygems'
|
@@ -8,31 +8,34 @@ require 'bundler/gem_tasks'
|
|
8
8
|
require 'benchmark/tasks'
|
9
9
|
|
10
10
|
require 'rspec/core/rake_task'
|
11
|
-
|
12
|
-
desc 'Default: run specs.'
|
13
|
-
task :default => :spec
|
11
|
+
require 'rubocop/rake_task'
|
14
12
|
|
15
13
|
RSpec::Core::RakeTask.new(:spec)
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task :default => ['compile:spec', 'compile:rpc', :spec, :rubocop]
|
16
17
|
|
17
18
|
desc 'Run specs'
|
18
19
|
namespace :compile do
|
19
20
|
|
20
21
|
desc 'Compile spec protos in spec/supprt/ directory'
|
21
|
-
task :spec do
|
22
|
+
task :spec do
|
22
23
|
proto_path = ::File.expand_path('../spec/support/', __FILE__)
|
23
|
-
|
24
|
+
proto_files = Dir[File.join(proto_path, '**', '*.proto')]
|
25
|
+
cmd = %(protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{proto_files.join(' ')})
|
24
26
|
|
25
27
|
puts cmd
|
26
|
-
|
28
|
+
system(cmd)
|
27
29
|
end
|
28
30
|
|
29
31
|
desc 'Compile rpc protos in protos/ directory'
|
30
|
-
task :rpc do
|
32
|
+
task :rpc do
|
31
33
|
proto_path = ::File.expand_path('../proto', __FILE__)
|
34
|
+
proto_files = Dir[File.join(proto_path, '**', '*.proto')]
|
32
35
|
output_dir = ::File.expand_path('../tmp/rpc', __FILE__)
|
33
36
|
::FileUtils.mkdir_p(output_dir)
|
34
37
|
|
35
|
-
cmd = %
|
38
|
+
cmd = %(protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{proto_files.join(' ')})
|
36
39
|
|
37
40
|
puts cmd
|
38
41
|
system(cmd)
|
@@ -41,7 +44,7 @@ namespace :compile do
|
|
41
44
|
'tmp/rpc/dynamic_discovery.pb.rb' => 'lib/protobuf/rpc',
|
42
45
|
'tmp/rpc/rpc.pb.rb' => 'lib/protobuf/rpc',
|
43
46
|
'tmp/rpc/google/protobuf/descriptor.pb.rb' => 'lib/protobuf/descriptors/google/protobuf',
|
44
|
-
'tmp/rpc/google/protobuf/compiler/plugin.pb.rb' => 'lib/protobuf/descriptors/google/protobuf/compiler'
|
47
|
+
'tmp/rpc/google/protobuf/compiler/plugin.pb.rb' => 'lib/protobuf/descriptors/google/protobuf/compiler',
|
45
48
|
}
|
46
49
|
|
47
50
|
files.each_pair do |source_file, destination_dir|
|
data/bin/protoc-gen-ruby
CHANGED
data/bin/rpc_server
CHANGED
data/install-protobuf.sh
ADDED
data/lib/protobuf.rb
CHANGED
@@ -5,32 +5,32 @@ require 'stringio'
|
|
5
5
|
|
6
6
|
require 'active_support/core_ext/object/blank'
|
7
7
|
require 'active_support/core_ext/object/try'
|
8
|
-
require 'active_support/notifications'
|
9
8
|
require 'active_support/inflector'
|
10
9
|
require 'active_support/json'
|
10
|
+
require 'active_support/notifications'
|
11
|
+
|
12
|
+
require 'protobuf/deprecation'
|
11
13
|
|
12
14
|
module Protobuf
|
13
15
|
|
14
16
|
# See Protobuf#connector_type documentation.
|
15
|
-
CONNECTORS = [
|
17
|
+
CONNECTORS = [:socket, :zmq].freeze
|
16
18
|
|
17
19
|
# Default is Socket as it has no external dependencies.
|
18
20
|
DEFAULT_CONNECTOR = :socket
|
19
21
|
|
20
22
|
module_function
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
class << self
|
25
|
+
# Client Host
|
26
|
+
#
|
27
|
+
# Default: `hostname` of the system
|
28
|
+
#
|
29
|
+
# The name or address of the host to use during client RPC calls.
|
30
|
+
attr_accessor :client_host
|
29
31
|
end
|
30
32
|
|
31
|
-
|
32
|
-
@_client_host = host
|
33
|
-
end
|
33
|
+
self.client_host = Socket.gethostname
|
34
34
|
|
35
35
|
# Connector Type
|
36
36
|
#
|
@@ -39,12 +39,12 @@ module Protobuf
|
|
39
39
|
# Symbol value which denotes the type of connector to use
|
40
40
|
# during client requests to an RPC server.
|
41
41
|
def self.connector_type
|
42
|
-
@
|
42
|
+
@connector_type ||= DEFAULT_CONNECTOR
|
43
43
|
end
|
44
44
|
|
45
45
|
def self.connector_type=(type)
|
46
|
-
|
47
|
-
@
|
46
|
+
fail ArgumentError, 'Invalid connector type given' unless CONNECTORS.include?(type)
|
47
|
+
@connector_type = type
|
48
48
|
end
|
49
49
|
|
50
50
|
# GC Pause during server requests
|
@@ -56,12 +56,19 @@ module Protobuf
|
|
56
56
|
# Once the request is completed, the GC is enabled again.
|
57
57
|
# This optomization provides a huge boost in speed to rpc requests.
|
58
58
|
def self.gc_pause_server_request?
|
59
|
-
return @
|
59
|
+
return @gc_pause_server_request unless @gc_pause_server_request.nil?
|
60
60
|
self.gc_pause_server_request = false
|
61
61
|
end
|
62
62
|
|
63
63
|
def self.gc_pause_server_request=(value)
|
64
|
-
@
|
64
|
+
@gc_pause_server_request = !!value
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.deprecator
|
68
|
+
@deprecator ||= Deprecation.new('4.0', to_s).tap do |deprecation|
|
69
|
+
deprecation.silenced = ENV.key?('PB_IGNORE_DEPRECATIONS')
|
70
|
+
deprecation.behavior = :stderr
|
71
|
+
end
|
65
72
|
end
|
66
73
|
|
67
74
|
# Print Deprecation Warnings
|
@@ -75,12 +82,11 @@ module Protobuf
|
|
75
82
|
#
|
76
83
|
# The rpc_server option will override the ENV setting.
|
77
84
|
def self.print_deprecation_warnings?
|
78
|
-
|
79
|
-
self.print_deprecation_warnings = ENV.key?('PB_IGNORE_DEPRECATIONS') ? false : true
|
85
|
+
!deprecator.silenced
|
80
86
|
end
|
81
87
|
|
82
88
|
def self.print_deprecation_warnings=(value)
|
83
|
-
|
89
|
+
deprecator.silenced = !value
|
84
90
|
end
|
85
91
|
|
86
92
|
# Permit unknown field on Message initialization
|
@@ -90,11 +96,11 @@ module Protobuf
|
|
90
96
|
# Simple boolean to define whether we want to permit unknown fields
|
91
97
|
# on Message intialization; otherwise a ::Protobuf::FieldNotDefinedError is thrown.
|
92
98
|
def self.ignore_unknown_fields?
|
93
|
-
!defined?(@
|
99
|
+
!defined?(@ignore_unknown_fields) || @ignore_unknown_fields
|
94
100
|
end
|
95
101
|
|
96
102
|
def self.ignore_unknown_fields=(value)
|
97
|
-
@
|
103
|
+
@ignore_unknown_fields = !!value
|
98
104
|
end
|
99
105
|
end
|
100
106
|
|
@@ -102,9 +108,9 @@ unless ENV.key?('PB_NO_NETWORKING')
|
|
102
108
|
require 'protobuf/rpc/client'
|
103
109
|
require 'protobuf/rpc/service'
|
104
110
|
|
105
|
-
env_connector_type = ENV.fetch('PB_CLIENT_TYPE')
|
111
|
+
env_connector_type = ENV.fetch('PB_CLIENT_TYPE') do
|
106
112
|
::Protobuf::DEFAULT_CONNECTOR
|
107
|
-
|
113
|
+
end.to_s.downcase.strip.to_sym
|
108
114
|
|
109
115
|
if ::Protobuf::CONNECTORS.include?(env_connector_type)
|
110
116
|
require "protobuf/#{env_connector_type}"
|
data/lib/protobuf/cli.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/core_ext/hash/keys'
|
2
|
+
|
1
3
|
require 'thor'
|
2
4
|
require 'protobuf/version'
|
3
5
|
require 'protobuf/logging'
|
@@ -9,7 +11,11 @@ module Protobuf
|
|
9
11
|
include ::Thor::Actions
|
10
12
|
include ::Protobuf::Logging
|
11
13
|
|
12
|
-
attr_accessor :runner, :mode
|
14
|
+
attr_accessor :runner, :mode, :exit_requested
|
15
|
+
|
16
|
+
no_commands do
|
17
|
+
alias_method :exit_requested?, :exit_requested
|
18
|
+
end
|
13
19
|
|
14
20
|
default_task :start
|
15
21
|
|
@@ -100,33 +106,34 @@ module Protobuf
|
|
100
106
|
# Re-write the $0 var to have a nice process name in ps.
|
101
107
|
def configure_process_name(app_file)
|
102
108
|
debug_say('Configuring process name')
|
103
|
-
$0 = "rpc_server --#{
|
109
|
+
$0 = "rpc_server --#{mode} #{options.host}:#{options.port} #{app_file}"
|
104
110
|
end
|
105
111
|
|
106
112
|
# Configure the mode of the server and the runner class.
|
107
113
|
def configure_runner_mode
|
108
114
|
debug_say('Configuring runner mode')
|
109
115
|
|
110
|
-
if multi_mode?
|
116
|
+
self.mode = if multi_mode?
|
111
117
|
say('WARNING: You have provided multiple mode options. Defaulting to socket mode.', :yellow)
|
112
|
-
|
118
|
+
:socket
|
113
119
|
elsif options.zmq?
|
114
|
-
|
115
|
-
else
|
120
|
+
:zmq
|
121
|
+
else # rubocop:disable Style/ElseAlignment
|
122
|
+
# above: https://github.com/bbatsov/rubocop/pull/1470/files
|
116
123
|
case server_type = ENV["PB_SERVER_TYPE"]
|
117
124
|
when nil, /socket/i
|
118
|
-
|
125
|
+
:socket
|
119
126
|
when /zmq/i
|
120
|
-
|
127
|
+
:zmq
|
121
128
|
else
|
122
129
|
say "WARNING: You have provided incorrect option 'PB_SERVER_TYPE=#{server_type}'. Defaulting to socket mode.", :yellow
|
123
|
-
|
130
|
+
:socket
|
124
131
|
end
|
125
132
|
end
|
126
133
|
end
|
127
134
|
|
128
135
|
# Configure signal traps.
|
129
|
-
# TODO add signal handling for hot-reloading the application.
|
136
|
+
# TODO: add signal handling for hot-reloading the application.
|
130
137
|
def configure_traps
|
131
138
|
debug_say('Configuring traps')
|
132
139
|
|
@@ -137,7 +144,7 @@ module Protobuf
|
|
137
144
|
debug_say("Registering trap for exit signal #{signal}", :blue)
|
138
145
|
|
139
146
|
trap(signal) do
|
140
|
-
|
147
|
+
self.exit_requested = true
|
141
148
|
shutdown_server
|
142
149
|
end
|
143
150
|
end
|
@@ -145,15 +152,15 @@ module Protobuf
|
|
145
152
|
|
146
153
|
# Create the runner for the configured mode
|
147
154
|
def create_runner
|
148
|
-
debug_say("Creating #{
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
155
|
+
debug_say("Creating #{mode} runner")
|
156
|
+
self.runner = case mode
|
157
|
+
when :zmq
|
158
|
+
create_zmq_runner
|
159
|
+
when :socket
|
160
|
+
create_socket_runner
|
161
|
+
else
|
162
|
+
say_and_exit("Unknown runner mode: #{mode}")
|
163
|
+
end
|
157
164
|
end
|
158
165
|
|
159
166
|
# Say something if we're in debug mode.
|
@@ -161,10 +168,6 @@ module Protobuf
|
|
161
168
|
say(message, color) if options.debug?
|
162
169
|
end
|
163
170
|
|
164
|
-
def exit_requested?
|
165
|
-
!!@exit_requested
|
166
|
-
end
|
167
|
-
|
168
171
|
# Internal helper to determine if the modes are multi-set which is not valid.
|
169
172
|
def multi_mode?
|
170
173
|
options.zmq? && options.socket?
|
@@ -179,8 +182,7 @@ module Protobuf
|
|
179
182
|
end
|
180
183
|
|
181
184
|
def runner_options
|
182
|
-
|
183
|
-
opt = options.inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
|
185
|
+
opt = options.symbolize_keys
|
184
186
|
|
185
187
|
opt[:workers_only] = (!!ENV['PB_WORKERS_ONLY']) || options.workers_only
|
186
188
|
|
@@ -206,18 +208,18 @@ module Protobuf
|
|
206
208
|
def create_socket_runner
|
207
209
|
require 'protobuf/socket'
|
208
210
|
|
209
|
-
|
211
|
+
self.runner = ::Protobuf::Rpc::SocketRunner.new(runner_options)
|
210
212
|
end
|
211
213
|
|
212
214
|
def create_zmq_runner
|
213
215
|
require 'protobuf/zmq'
|
214
216
|
|
215
|
-
|
217
|
+
self.runner = ::Protobuf::Rpc::ZmqRunner.new(runner_options)
|
216
218
|
end
|
217
219
|
|
218
220
|
def shutdown_server
|
219
221
|
logger.info { 'RPC Server shutting down...' }
|
220
|
-
|
222
|
+
runner.stop
|
221
223
|
::Protobuf::Rpc::ServiceDirectory.instance.stop
|
222
224
|
end
|
223
225
|
|
@@ -225,17 +227,15 @@ module Protobuf
|
|
225
227
|
def start_server
|
226
228
|
debug_say('Running server')
|
227
229
|
|
228
|
-
|
229
|
-
logger.info
|
230
|
-
"pid #{::Process.pid} -- #{
|
231
|
-
|
230
|
+
runner.run do
|
231
|
+
logger.info do
|
232
|
+
"pid #{::Process.pid} -- #{mode} RPC Server listening at #{options.host}:#{options.port}"
|
233
|
+
end
|
232
234
|
|
233
235
|
::ActiveSupport::Notifications.instrument("after_server_bind")
|
234
236
|
end
|
235
237
|
|
236
238
|
logger.info { 'Shutdown complete' }
|
237
|
-
|
238
|
-
exit 0
|
239
239
|
end
|
240
240
|
end
|
241
241
|
end
|