gruf-queue 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3e95a6295c2e8ac7b60fe83ed35b1b7a5162006bebc94be3548f20745750f7a
4
- data.tar.gz: 428cabc63371c929881d0b99d4f58d83191faa41197b6cb965b52d41b9e1fb1b
3
+ metadata.gz: b0aed8b2822b571278254b3fa5838fcee2bd1c709ce7397bf4dbe9fc296f8847
4
+ data.tar.gz: e4972e7017721f7c6d1f2924c6b362bb0bb08705b4ef63b31f9ee2465904d953
5
5
  SHA512:
6
- metadata.gz: e552084a711dfaf6138ddcc099e01b95e6bb16919fc9e761c22aece0161d04bf553af6fed09008b3d4bff7d6250da824b10fdc01a7c35670bd8e2697c734fe1b
7
- data.tar.gz: 82fa9aaa6741155b10790a656672df0a9f5fba8714fa81ad2eab1142ae5ad1b67e4302d0f6eeb3f6431f0c89187a4aa9f857e374c001bfe0eeb2b32d4e4858bf
6
+ metadata.gz: '09802fce427e339133d11fd72776a61061334e0b29e38e28628a636948830b48280fdc6b89e60dedad2e4a6fcce6355e21c1c1c79ff3c27691697f4eac560624'
7
+ data.tar.gz: 26ae3647141bc9bee23607743bc94c19f42a2b7bd81bf3a9440c3bd6f86d01122c1b4e5f81144ee6a009595aa445e685cc7f33bba5fdf604a07acacb013182df
@@ -13,102 +13,144 @@ module Gruf
13
13
  # @example Check installation status
14
14
  # Gruf::Queue::Plugin.installed? # => true
15
15
  class Plugin
16
- # Install and configure the gruf-queue plugin.
17
- # This method is idempotent and can be called multiple times safely.
18
- #
19
- # @return [Boolean] true if installation completed, false if already installed
20
- def self.install!
21
- return false if @installed
22
-
23
- begin
24
- # Configure Gruf with queue-specific settings
25
- Configuration.configure unless Configuration.configured?
26
-
27
- # Configure Gruf with all queue-specific settings
28
- Gruf.configure do |config|
29
- configure_rpc_server(config)
30
- configure_interceptors(config)
16
+ class << self
17
+ # Install and configure the gruf-queue plugin.
18
+ # This method is idempotent and can be called multiple times safely.
19
+ #
20
+ # @return [Boolean] true if installation completed, false if already installed
21
+ def install!
22
+ return false if @installed
23
+
24
+ begin
25
+ # Configure Gruf with queue-specific settings
26
+ Configuration.configure unless Configuration.configured?
27
+
28
+ # Configure Gruf with all queue-specific settings
29
+ Gruf.configure do |config|
30
+ configure_rpc_server(config)
31
+ configure_interceptors(config)
32
+ end
33
+
34
+ @installed = true
35
+ true
36
+ rescue StandardError => e
37
+ # Log the error but don't raise to avoid breaking the application startup
38
+ log_installation_error(e)
39
+ false
31
40
  end
41
+ end
32
42
 
33
- @installed = true
34
- true
35
- rescue StandardError => e
36
- # Log the error but don't raise to avoid breaking the application startup
37
- log_installation_error(e)
38
- false
43
+ # Check installation status.
44
+ #
45
+ # @return [Boolean] true if installed, false otherwise
46
+ def installed?
47
+ !!@installed
39
48
  end
40
- end
41
49
 
42
- # Check installation status.
43
- #
44
- # @return [Boolean] true if installed, false otherwise
45
- def self.installed?
46
- !!@installed
47
- end
50
+ # Reset installation state for testing.
51
+ #
52
+ # @return [void]
53
+ def reset!
54
+ @installed = false
55
+ # Also reset the configuration state
56
+ Configuration.reset! if Configuration.respond_to?(:reset!)
57
+ end
48
58
 
49
- # Reset installation state for testing.
50
- #
51
- # @return [void]
52
- def self.reset!
53
- @installed = false
54
- # Also reset the configuration state
55
- Configuration.reset! if Configuration.respond_to?(:reset!)
56
- end
59
+ private
57
60
 
58
- # Configure RPC server to use QueuedRpcServer.
59
- #
60
- # @param config [Object] Gruf configuration object
61
- # @return [void]
62
- # @api private
63
- private_class_method def self.configure_rpc_server(config)
64
- config.rpc_server = QueuedRpcServer
65
- end
61
+ # Configure RPC server to use QueuedRpcServer.
62
+ #
63
+ # @param config [Object] Gruf configuration object
64
+ # @return [void]
65
+ # @api private
66
+ def configure_rpc_server(config)
67
+ config.rpc_server = QueuedRpcServer
68
+ end
66
69
 
67
- # Configure interceptors if ActiveRecord is available.
68
- #
69
- # @param config [Object] Gruf configuration object
70
- # @return [void]
71
- # @api private
72
- private_class_method def self.configure_interceptors(config)
73
- return unless defined?(ActiveRecord)
74
-
75
- validate_active_record_availability
76
-
77
- config.interceptors.use(
78
- Interceptors::ConnectionReset,
79
- enabled: true,
80
- target_classes: [ActiveRecord::Base],
81
- )
82
- end
70
+ # Configure interceptors if ActiveRecord is available.
71
+ #
72
+ # @param config [Object] Gruf configuration object
73
+ # @return [void]
74
+ # @api private
75
+ def configure_interceptors(config)
76
+ return unless defined?(ActiveRecord)
83
77
 
84
- # Validate ActiveRecord connection handler availability.
85
- #
86
- # @raise [StandardError] if ActiveRecord doesn't support connection_handler
87
- # @return [void]
88
- # @api private
89
- private_class_method def self.validate_active_record_availability
90
- return if ActiveRecord::Base.respond_to?(:connection_handler)
78
+ validate_active_record_availability
79
+ ensure_interceptors_registry_available(config)
91
80
 
92
- raise StandardError, 'ActiveRecord::Base does not support connection_handler'
93
- end
81
+ config.interceptors.use(
82
+ Interceptors::ConnectionReset,
83
+ enabled: true,
84
+ target_classes: [ActiveRecord::Base],
85
+ )
86
+ end
87
+
88
+ # Validate ActiveRecord connection handler availability.
89
+ #
90
+ # @raise [StandardError] if ActiveRecord doesn't support connection_handler
91
+ # @return [void]
92
+ # @api private
93
+ def validate_active_record_availability
94
+ return if ActiveRecord::Base.respond_to?(:connection_handler)
94
95
 
95
- # Log installation error using available logger.
96
- #
97
- # @param error [StandardError] Error to log
98
- # @return [void]
99
- # @api private
100
- private_class_method def self.log_installation_error(error)
101
- message = "Failed to install gruf-queue plugin: #{error.message}"
102
-
103
- # Skip error logging in test environment
104
- return if ENV['RACK_ENV'] == 'test' || ENV['RAILS_ENV'] == 'test' || defined?(RSpec)
105
-
106
- if defined?(Rails) && Rails.logger && Rails.logger.respond_to?(:error)
107
- Rails.logger.error(message)
108
- elsif defined?(GRPC) && GRPC.logger && GRPC.logger.respond_to?(:error)
109
- GRPC.logger.error(message)
110
- else
111
- warn message
96
+ raise StandardError, 'ActiveRecord::Base does not support connection_handler'
97
+ end
98
+
99
+ # Ensure interceptors registry is available and initialized.
100
+ #
101
+ # Handles Rails initialization timing issues where gruf-queue loads
102
+ # before Gruf's configuration is fully initialized.
103
+ #
104
+ # @param config [Object] Gruf configuration object
105
+ # @return [void]
106
+ # @raise [StandardError] if interceptors registry cannot be initialized
107
+ # @api private
108
+ def ensure_interceptors_registry_available(config)
109
+ # Check if interceptors registry exists and is initialized
110
+ return if config.respond_to?(:interceptors) && !config.interceptors.nil?
111
+
112
+ # Initialize interceptors registry if missing
113
+ begin
114
+ require 'gruf/interceptors/registry'
115
+ rescue LoadError => e
116
+ raise StandardError, "Failed to load Gruf interceptors registry: #{e.message}"
117
+ end
118
+
119
+ if config.respond_to?(:interceptors=)
120
+ config.interceptors = ::Gruf::Interceptors::Registry.new
121
+ elsif config.respond_to?(:define_singleton_method)
122
+ # Fallback: define interceptors accessor methods dynamically
123
+ registry = ::Gruf::Interceptors::Registry.new
124
+ config.define_singleton_method(:interceptors) { registry }
125
+ config.define_singleton_method(:interceptors=) { |val| registry = val }
126
+ else
127
+ raise StandardError, 'Cannot initialize interceptors registry: configuration object lacks required methods'
128
+ end
129
+
130
+ # Verify initialization was successful
131
+ return if config.respond_to?(:interceptors) && config.interceptors.respond_to?(:use)
132
+
133
+ raise StandardError, 'Interceptors registry initialization failed: missing use method'
134
+ end
135
+
136
+ # Log installation error using available logger.
137
+ #
138
+ # @param error [StandardError] Error to log
139
+ # @return [void]
140
+ # @api private
141
+ def log_installation_error(error)
142
+ message = "Failed to install gruf-queue plugin: #{error.message}"
143
+
144
+ # Skip error logging in test environment
145
+ return if ENV['RACK_ENV'] == 'test' || ENV['RAILS_ENV'] == 'test' || defined?(RSpec)
146
+
147
+ if defined?(Rails) && Rails.logger.respond_to?(:error)
148
+ Rails.logger.error(message)
149
+ elsif defined?(GRPC) && GRPC.logger.respond_to?(:error)
150
+ GRPC.logger.error(message)
151
+ else
152
+ warn message
153
+ end
112
154
  end
113
155
  end
114
156
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gruf
4
4
  module Queue
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gruf-queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ether Moon