protobuf-nats 0.1.1 → 0.1.2

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: ee1af2d977263e468709cdfaa78d0d4819f0ae7e
4
- data.tar.gz: fc9664c48ba9ac1dab3660d21011d87aac49c25e
3
+ metadata.gz: 5e444dd3193486c805f44d670ca6aceca10f7df3
4
+ data.tar.gz: 2f0ed9b4431fc0379f41348fca8820dc57953421
5
5
  SHA512:
6
- metadata.gz: f090b4fbeaa265db5e9c2694b1ebd9608209efd52d55a7af10719a4a0328ee9ba47eed27c246a21971e5f12640c320ef66ed3d5dcdb9c7cac88bfa87cec40d05
7
- data.tar.gz: 5ae55860c6c42dae98c209e40508987c2fd505e733e6693cefabf718e3d9914c78779571aad8ce4addf7ce291c3a1c3aa1a9d5df2d372d670ca68ed88a26355e
6
+ metadata.gz: b99622db5416e0626861531c8777f9207a23b5a3afba48211db0bf312f92fee1f49e71eeca0dc5621614b6452c439c96c329546281b823c2563a41a9f167f6bd
7
+ data.tar.gz: a0a52c9c909f552a2b01bfce3eb0a9fc18b2fd424f99c9c8301182526dd9ea69bac3bbdab5977f3b1f06f6efe79230ceb9fe332973d921dea86439e7b94fbdbe
@@ -6,6 +6,7 @@ require "protobuf/nats"
6
6
  module Protobuf
7
7
  module Nats
8
8
  class Runner
9
+ include ::Protobuf::Logging
9
10
 
10
11
  def initialize(options)
11
12
  @options = case
@@ -1,5 +1,4 @@
1
1
  require "active_support/core_ext/class/subclasses"
2
- require "protobuf/nats/fixed_thread_pool_with_no_queue"
3
2
  require "protobuf/rpc/server"
4
3
  require "protobuf/rpc/service"
5
4
 
@@ -19,7 +18,7 @@ module Protobuf
19
18
  @nats = options[:client] || ::NATS::IO::Client.new
20
19
  @nats.connect(::Protobuf::Nats.config.connection_options)
21
20
 
22
- @thread_pool = ::Protobuf::Nats::FixedThreadPoolWithNoQueue.new(options[:threads])
21
+ @thread_pool = ::Concurrent::FixedThreadPool.new(options[:threads], :max_queue => options[:threads])
23
22
 
24
23
  @subscriptions = []
25
24
  end
@@ -29,9 +28,7 @@ module Protobuf
29
28
  end
30
29
 
31
30
  def execute_request_promise(request_data, reply_id)
32
- ::Concurrent::Promise.new(:executor => thread_pool).then do
33
- # Publish an ACK.
34
- nats.publish(reply_id, ::Protobuf::Nats::Messages::ACK)
31
+ promise = ::Concurrent::Promise.new(:executor => thread_pool).then do
35
32
  # Process request.
36
33
  response_data = handle_request(request_data)
37
34
  # Publish response.
@@ -42,6 +39,11 @@ module Protobuf
42
39
  logger.error error.backtrace.join("\n")
43
40
  end
44
41
  end.execute
42
+
43
+ # Publish an ACK to signal the server has picked up the work.
44
+ nats.publish(reply_id, ::Protobuf::Nats::Messages::ACK)
45
+
46
+ promise
45
47
  rescue ::Concurrent::RejectedExecutionError
46
48
  nil
47
49
  end
@@ -1,5 +1,5 @@
1
1
  module Protobuf
2
2
  module Nats
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
data/lib/protobuf/nats.rb CHANGED
@@ -4,8 +4,7 @@ require "protobuf"
4
4
  # We don't need this, but the CLI attempts to terminate.
5
5
  require "protobuf/rpc/service_directory"
6
6
 
7
- require "connection_pool"
8
-
7
+ require "concurrent"
9
8
  require "nats/io/client"
10
9
 
11
10
  require "protobuf/nats/client"
@@ -30,8 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_runtime_dependency "protobuf", "3.7.0.pre3"
34
- spec.add_runtime_dependency "connection_pool"
33
+ spec.add_runtime_dependency "protobuf", "~> 3.7"
35
34
  spec.add_runtime_dependency "concurrent-ruby"
36
35
  spec.add_runtime_dependency "nats-pure"
37
36
 
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protobuf-nats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Dewitt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-27 00:00:00.000000000 Z
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: protobuf
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
18
- - !ruby/object:Gem::Version
19
- version: 3.7.0.pre3
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '='
25
- - !ruby/object:Gem::Version
26
- version: 3.7.0.pre3
27
- - !ruby/object:Gem::Dependency
28
- name: connection_pool
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
17
+ - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '0'
19
+ version: '3.7'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - ">="
24
+ - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '3.7'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: concurrent-ruby
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -161,7 +147,6 @@ files:
161
147
  - lib/protobuf/nats.rb
162
148
  - lib/protobuf/nats/client.rb
163
149
  - lib/protobuf/nats/config.rb
164
- - lib/protobuf/nats/fixed_thread_pool_with_no_queue.rb
165
150
  - lib/protobuf/nats/runner.rb
166
151
  - lib/protobuf/nats/server.rb
167
152
  - lib/protobuf/nats/version.rb
@@ -1,32 +0,0 @@
1
- require "concurrent"
2
-
3
- module Protobuf
4
- module Nats
5
- class FixedThreadPoolWithNoQueue < ::Concurrent::FixedThreadPool
6
- def ns_initialize(opts)
7
- min_length = opts.fetch(:min_threads, DEFAULT_MIN_POOL_SIZE).to_i
8
- max_length = opts.fetch(:max_threads, DEFAULT_MAX_POOL_SIZE).to_i
9
- idletime = opts.fetch(:idletime, DEFAULT_THREAD_IDLETIMEOUT).to_i
10
- @fallback_policy = opts.fetch(:fallback_policy, :abort)
11
-
12
- if ::Concurrent.on_jruby?
13
- super(opts)
14
-
15
- # We need to use a synchronous queue to ensure we only perform work
16
- # when a thread is available.
17
- queue = java.util.concurrent.SynchronousQueue.new
18
- @executor = java.util.concurrent.ThreadPoolExecutor.new(
19
- min_length, max_length,
20
- idletime, java.util.concurrent.TimeUnit::SECONDS,
21
- queue, FALLBACK_POLICY_CLASSES[@fallback_policy].new)
22
- else
23
- # MRI will take a max queue of -1 to mean no queue.
24
- opts[:max_queue] = -1
25
- super(opts)
26
- end
27
-
28
- @max_queue = -1
29
- end
30
- end
31
- end
32
- end