forest_admin_rpc_agent 1.13.4 → 1.14.0
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/config/routes.rb +13 -8
- data/lib/forest_admin_rpc_agent/http/router.rb +92 -0
- data/lib/forest_admin_rpc_agent/version.rb +1 -1
- data/lib/forest_admin_rpc_agent.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9fb58efd1964b8dbf5c8e9c10b6557297196df287759952fdeff7eef3949e836
|
|
4
|
+
data.tar.gz: 01f76fae8c2ee42d73cd2e454fe9bdaee2a16aea47cf37e38081af45931e884e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 25c49b286bce40a650d73bf684ca6b50b6bd5dfec85d546f5460dfc64dd4babaf01fd67d45f05fea865ab69d94490e53f65626ebc186eb03f3f3c5815680b6de
|
|
7
|
+
data.tar.gz: 3507ba4f38bb3b4344f47958899d797e11a53e8aece6ab3e2cd45b2201630f84b3d7d82bdf4b427cbc87cdf22118dedb9b5bb01ff84d41021211afde3728b36b
|
data/config/routes.rb
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
ForestAdminRpcAgent::Engine.routes.draw do
|
|
2
|
-
|
|
2
|
+
next if defined?(Rake) && Rake.respond_to?(:application) && Rake.application&.top_level_tasks&.any?
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
route_instance = route_class.new
|
|
8
|
-
if route_instance.respond_to?(:registered)
|
|
4
|
+
begin
|
|
5
|
+
# Use cached_route_instances to avoid recomputing routes during Rails initialization
|
|
6
|
+
ForestAdminRpcAgent::Http::Router.cached_route_instances.each do |route_instance|
|
|
9
7
|
route_instance.registered(self)
|
|
10
|
-
else
|
|
11
|
-
Rails.logger.warn "Skipping route: #{route_class} (does not respond to :registered)"
|
|
12
8
|
end
|
|
9
|
+
rescue StandardError => e
|
|
10
|
+
error_message = "[ForestAdminRpcAgent] CRITICAL: Failed to initialize routes: #{e.class} - #{e.message}\n" \
|
|
11
|
+
"#{e.backtrace.join("\n")}"
|
|
12
|
+
begin
|
|
13
|
+
ForestAdminRpcAgent::Facades::Container.logger.log('Error', error_message)
|
|
14
|
+
rescue StandardError
|
|
15
|
+
puts error_message
|
|
16
|
+
end
|
|
17
|
+
raise e
|
|
13
18
|
end
|
|
14
19
|
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
module ForestAdminRpcAgent
|
|
2
|
+
module Http
|
|
3
|
+
class Router
|
|
4
|
+
# Mutex for thread-safe cache operations
|
|
5
|
+
@mutex = Mutex.new
|
|
6
|
+
|
|
7
|
+
def self.cached_route_instances
|
|
8
|
+
return route_instances.freeze if cache_disabled?
|
|
9
|
+
|
|
10
|
+
return @cached_route_instances if @cached_route_instances
|
|
11
|
+
|
|
12
|
+
@mutex.synchronize do
|
|
13
|
+
@cached_route_instances ||= begin
|
|
14
|
+
start_time = Time.now
|
|
15
|
+
computed_routes = route_instances
|
|
16
|
+
elapsed = ((Time.now - start_time) * 1000).round(2)
|
|
17
|
+
|
|
18
|
+
log_message = "[ForestAdminRpcAgent] Computed #{computed_routes.size} routes " \
|
|
19
|
+
"in #{elapsed}ms (caching enabled)"
|
|
20
|
+
log_to_available_logger('Info', log_message)
|
|
21
|
+
|
|
22
|
+
computed_routes.freeze
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.cache_disabled?
|
|
28
|
+
config = ForestAdminRpcAgent::Facades::Container.config_from_cache
|
|
29
|
+
config&.dig(:disable_route_cache) == true
|
|
30
|
+
rescue StandardError
|
|
31
|
+
# Config not available, default to caching enabled
|
|
32
|
+
false
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.reset_cached_route_instances!
|
|
36
|
+
@mutex.synchronize do
|
|
37
|
+
@cached_route_instances = nil
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.log_to_available_logger(level, message)
|
|
42
|
+
ForestAdminRpcAgent::Facades::Container.logger.log(level, message)
|
|
43
|
+
rescue StandardError
|
|
44
|
+
puts message
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.route_instances
|
|
48
|
+
route_classes = ForestAdminRpcAgent::Routes.constants.reject { |route| route.to_s == 'BaseRoute' }
|
|
49
|
+
|
|
50
|
+
route_instances = []
|
|
51
|
+
|
|
52
|
+
route_classes.each do |route_name|
|
|
53
|
+
route_class = ForestAdminRpcAgent::Routes.const_get(route_name)
|
|
54
|
+
|
|
55
|
+
# Skip if it's not a class or if it doesn't look like a route
|
|
56
|
+
unless route_class.is_a?(Class)
|
|
57
|
+
log_to_available_logger(
|
|
58
|
+
'Warn',
|
|
59
|
+
"Skipping constant: #{route_name} (not a class)"
|
|
60
|
+
)
|
|
61
|
+
next
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
begin
|
|
65
|
+
route_instance = route_class.new
|
|
66
|
+
|
|
67
|
+
unless route_instance.respond_to?(:registered)
|
|
68
|
+
log_to_available_logger(
|
|
69
|
+
'Warn',
|
|
70
|
+
"Skipping route: #{route_class} (does not respond to :registered)"
|
|
71
|
+
)
|
|
72
|
+
next
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
route_instances << route_instance
|
|
76
|
+
rescue ArgumentError => e
|
|
77
|
+
# Skip classes that require constructor arguments (not routes)
|
|
78
|
+
log_to_available_logger(
|
|
79
|
+
'Warn',
|
|
80
|
+
"Skipping constant: #{route_name} (requires constructor arguments: #{e.message})"
|
|
81
|
+
)
|
|
82
|
+
next
|
|
83
|
+
rescue StandardError => e
|
|
84
|
+
raise e.class, "Failed to instantiate route '#{route_name}': #{e.message}"
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
route_instances
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: forest_admin_rpc_agent
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matthieu
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2025-11-
|
|
12
|
+
date: 2025-11-07 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: base64
|
|
@@ -162,6 +162,7 @@ files:
|
|
|
162
162
|
- lib/forest_admin_rpc_agent/extensions/config_loader.rb
|
|
163
163
|
- lib/forest_admin_rpc_agent/extensions/sinatra_extension.rb
|
|
164
164
|
- lib/forest_admin_rpc_agent/facades/container.rb
|
|
165
|
+
- lib/forest_admin_rpc_agent/http/router.rb
|
|
165
166
|
- lib/forest_admin_rpc_agent/middleware/authentication.rb
|
|
166
167
|
- lib/forest_admin_rpc_agent/routes/action_execute.rb
|
|
167
168
|
- lib/forest_admin_rpc_agent/routes/action_form.rb
|