gruf 2.16.2 → 2.17.0

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: f0508561578b2ebd6490bebfeeee8f4442d4bcec1d1cb877dc0005933564fc33
4
- data.tar.gz: b4130a47d10681a4876046aa782640091799d99f433cc5f6ae55f6dce1f60ecf
3
+ metadata.gz: feddcb49d9325078dfb0d7367f5e82dfea0d46a82e56784b10484c873ab375a5
4
+ data.tar.gz: b4614f08c2b6d8f62edfc1f34be0dffc7af4825b680e49aaf5c6160315314d32
5
5
  SHA512:
6
- metadata.gz: 1a9e198be4481b4e56c3e57fb7d76be2ce97e6cbe30368fadc990a505d1864c98f1e0d25f02c8209a0dafd89021537b15f6f12a83323ec3c8a7ff114c7c8094b
7
- data.tar.gz: 5fc8489af23aa0e387aa84dc4104e7812aa0a767ddb32e6bf83f331442b79073f57c5ef97b2326ff9ec64cebf018d76589ce5f964bf67a69e758dd0780508423
6
+ metadata.gz: 3e67b5fdaf175a0c8b839532d6024415f12c1fdbd91f44fdec5cfa1ac0d7c33e821b740a192f251664f6ff09ef5dc96d903c480a474d2f53d4b876189023550c
7
+ data.tar.gz: 4061112bf7ea91180fb5ea16d5d135cc3a1a7dab7d94ba479d462f3acca3aa183373f64eb5d8e7d9ad0442a457ed5b25e806e407f27c9d3c6ee0658d153b654c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@ Changelog for the gruf gem. This includes internal history before the gem was ma
2
2
 
3
3
  ### Pending release
4
4
 
5
+ ### 2.17.0
6
+
7
+ * [#179] Add Ruby 3.2 support
8
+ * [#178] Introduce read-write lock for code reloading; cover controller class resolution with code reloading.
9
+ * [#180] Support multiple databases connection reset in `Gruf::Interceptors::ActiveRecord::ConnectionReset`.
10
+
5
11
  ### 2.16.2
6
12
 
7
13
  * [#175] Fix code reload thread-safety. Calls to `Zeitwerk::Loader#setup` are now made in a thread-safe manner.
data/README.md CHANGED
@@ -17,7 +17,7 @@ up fast and efficiently at scale. Some of its features include:
17
17
  still preserving gRPC BadStatus codes
18
18
  * Server and client execution timings in responses
19
19
 
20
- gruf currently has active support for gRPC 1.10.x+. gruf is compatible and tested with Ruby 2.6-3.1.
20
+ gruf currently has active support for gRPC 1.10.x+. gruf is compatible and tested with Ruby 2.6-3.2.
21
21
  gruf is also not [Rails](https://github.com/rails/rails)-specific, and can be used in any Ruby framework
22
22
  (such as [Grape](https://github.com/ruby-grape/grape) or [dry-rb](https://dry-rb.org/), for instance).
23
23
 
data/gruf.gemspec CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.executables << 'gruf'
33
33
  spec.require_paths = ['lib']
34
34
 
35
- spec.required_ruby_version = '>= 2.7', '< 3.2'
35
+ spec.required_ruby_version = '>= 2.7', '< 3.3'
36
36
 
37
37
  spec.metadata = {
38
38
  'bug_tracker_uri' => 'https://github.com/bigcommerce/gruf/issues',
@@ -15,6 +15,8 @@
15
15
  # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
16
  # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
17
  #
18
+ require 'concurrent/atomic/read_write_lock'
19
+
18
20
  module Gruf
19
21
  module Controllers
20
22
  ##
@@ -47,10 +49,19 @@ module Gruf
47
49
  # Reload all files managed by the autoloader, if reloading is enabled
48
50
  #
49
51
  def reload
50
- if @reloading_enabled
51
- reload_mutex do
52
- @loader.reload
53
- end
52
+ return unless @reloading_enabled
53
+
54
+ reload_lock.with_write_lock do
55
+ @loader.reload
56
+ end
57
+ end
58
+
59
+ def with_fresh_controller(controller_name)
60
+ return yield(controller_name.constantize) unless @reloading_enabled
61
+
62
+ ::Gruf::Autoloaders.reload
63
+ reload_lock.with_read_lock do
64
+ yield(controller_name.constantize)
54
65
  end
55
66
  end
56
67
 
@@ -77,12 +88,8 @@ module Gruf
77
88
  ##
78
89
  # Handle thread-safe access to the loader
79
90
  #
80
- def reload_mutex(&block)
81
- @reload_mutex ||= begin
82
- require 'monitor'
83
- Monitor.new
84
- end
85
- @reload_mutex.synchronize(&block)
91
+ def reload_lock
92
+ @reload_lock ||= Concurrent::ReadWriteLock.new
86
93
  end
87
94
  end
88
95
  end
@@ -90,7 +90,6 @@ module Gruf
90
90
  # @param [block] &block The passed block for executing the method
91
91
  #
92
92
  def call(method_key, &block)
93
- ::Gruf.autoloaders.reload if ::Gruf.development?
94
93
  Interceptors::Context.new(@interceptors).intercept! do
95
94
  process_action(method_key, &block)
96
95
  end
@@ -46,54 +46,59 @@ module Gruf
46
46
  #
47
47
  def bind_method(service_ref, controller, method_name, desc)
48
48
  method_key = method_name.to_s.underscore.to_sym
49
+ controller_name = controller.name
49
50
  service_ref.class_eval do
50
51
  if desc.request_response?
51
52
  define_method(method_key) do |message, active_call|
52
- controller = controller.name.constantize
53
- c = controller.new(
54
- method_key: method_key,
55
- service: service_ref,
56
- message: message,
57
- active_call: active_call,
58
- rpc_desc: desc
59
- )
60
- c.call(method_key)
53
+ Gruf::Autoloaders.controllers.with_fresh_controller(controller_name) do |fresh_controller|
54
+ c = fresh_controller.new(
55
+ method_key: method_key,
56
+ service: service_ref,
57
+ message: message,
58
+ active_call: active_call,
59
+ rpc_desc: desc
60
+ )
61
+ c.call(method_key)
62
+ end
61
63
  end
62
64
  elsif desc.client_streamer?
63
65
  define_method(method_key) do |active_call|
64
- controller = controller.name.constantize
65
- c = controller.new(
66
- method_key: method_key,
67
- service: service_ref,
68
- message: proc { |&block| active_call.each_remote_read(&block) },
69
- active_call: active_call,
70
- rpc_desc: desc
71
- )
72
- c.call(method_key)
66
+ Gruf::Autoloaders.controllers.with_fresh_controller(controller_name) do |fresh_controller|
67
+ c = fresh_controller.new(
68
+ method_key: method_key,
69
+ service: service_ref,
70
+ message: proc { |&block| active_call.each_remote_read(&block) },
71
+ active_call: active_call,
72
+ rpc_desc: desc
73
+ )
74
+ c.call(method_key)
75
+ end
73
76
  end
74
77
  elsif desc.server_streamer?
75
78
  define_method(method_key) do |message, active_call, &block|
76
- controller = controller.name.constantize
77
- c = controller.new(
78
- method_key: method_key,
79
- service: service_ref,
80
- message: message,
81
- active_call: active_call,
82
- rpc_desc: desc
83
- )
84
- c.call(method_key, &block)
79
+ Gruf::Autoloaders.controllers.with_fresh_controller(controller_name) do |fresh_controller|
80
+ c = fresh_controller.new(
81
+ method_key: method_key,
82
+ service: service_ref,
83
+ message: message,
84
+ active_call: active_call,
85
+ rpc_desc: desc
86
+ )
87
+ c.call(method_key, &block)
88
+ end
85
89
  end
86
90
  else # bidi
87
91
  define_method(method_key) do |messages, active_call, &block|
88
- controller = controller.name.constantize
89
- c = controller.new(
90
- method_key: method_key,
91
- service: service_ref,
92
- message: messages,
93
- active_call: active_call,
94
- rpc_desc: desc
95
- )
96
- c.call(method_key, &block)
92
+ Gruf::Autoloaders.controllers.with_fresh_controller(controller_name) do |fresh_controller|
93
+ c = fresh_controller.new(
94
+ method_key: method_key,
95
+ service: service_ref,
96
+ message: messages,
97
+ active_call: active_call,
98
+ rpc_desc: desc
99
+ )
100
+ c.call(method_key, &block)
101
+ end
97
102
  end
98
103
  end
99
104
  end
@@ -27,11 +27,13 @@ module Gruf
27
27
  # connection pool, we need to ensure that this is done to properly
28
28
  #
29
29
  def call
30
- ::ActiveRecord::Base.establish_connection if enabled? && !::ActiveRecord::Base.connection.active?
30
+ if enabled?
31
+ target_classes.each { |klass| klass.establish_connection unless klass.connection.active? }
32
+ end
31
33
 
32
34
  yield
33
35
  ensure
34
- ::ActiveRecord::Base.clear_active_connections! if enabled?
36
+ target_classes.each(&:clear_active_connections!) if enabled?
35
37
  end
36
38
 
37
39
  private
@@ -42,6 +44,13 @@ module Gruf
42
44
  def enabled?
43
45
  defined?(::ActiveRecord::Base)
44
46
  end
47
+
48
+ ##
49
+ # @return [Array<Class>] The list of ActiveRecord classes to reset
50
+ #
51
+ def target_classes
52
+ options[:target_classes] || [::ActiveRecord::Base]
53
+ end
45
54
  end
46
55
  end
47
56
  end
data/lib/gruf/version.rb CHANGED
@@ -16,5 +16,5 @@
16
16
  # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
17
  #
18
18
  module Gruf
19
- VERSION = '2.16.2'
19
+ VERSION = '2.17.0'
20
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gruf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.16.2
4
+ version: 2.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun McCormick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-21 00:00:00.000000000 Z
11
+ date: 2023-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler-audit
@@ -399,14 +399,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
399
399
  version: '2.7'
400
400
  - - "<"
401
401
  - !ruby/object:Gem::Version
402
- version: '3.2'
402
+ version: '3.3'
403
403
  required_rubygems_version: !ruby/object:Gem::Requirement
404
404
  requirements:
405
405
  - - ">="
406
406
  - !ruby/object:Gem::Version
407
407
  version: '0'
408
408
  requirements: []
409
- rubygems_version: 3.3.3
409
+ rubygems_version: 3.4.1
410
410
  signing_key:
411
411
  specification_version: 4
412
412
  summary: gRPC Ruby Framework