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 +4 -4
- data/lib/gruf/queue/plugin.rb +128 -86
- data/lib/gruf/queue/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0aed8b2822b571278254b3fa5838fcee2bd1c709ce7397bf4dbe9fc296f8847
|
4
|
+
data.tar.gz: e4972e7017721f7c6d1f2924c6b362bb0bb08705b4ef63b31f9ee2465904d953
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09802fce427e339133d11fd72776a61061334e0b29e38e28628a636948830b48280fdc6b89e60dedad2e4a6fcce6355e21c1c1c79ff3c27691697f4eac560624'
|
7
|
+
data.tar.gz: 26ae3647141bc9bee23607743bc94c19f42a2b7bd81bf3a9440c3bd6f86d01122c1b4e5f81144ee6a009595aa445e685cc7f33bba5fdf604a07acacb013182df
|
data/lib/gruf/queue/plugin.rb
CHANGED
@@ -13,102 +13,144 @@ module Gruf
|
|
13
13
|
# @example Check installation status
|
14
14
|
# Gruf::Queue::Plugin.installed? # => true
|
15
15
|
class Plugin
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
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
|
-
|
93
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
#
|
104
|
-
return
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
data/lib/gruf/queue/version.rb
CHANGED