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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d53c87e67caf6c3d8d25e0153e5e2d9d70c9c2729068a8fdf9b1ae87fc1d2a9c
4
- data.tar.gz: 33e47c98fa34e2334d1e11a6bf24a4402d3d71ef7fee86339de5b5a201577c96
3
+ metadata.gz: 9fb58efd1964b8dbf5c8e9c10b6557297196df287759952fdeff7eef3949e836
4
+ data.tar.gz: 01f76fae8c2ee42d73cd2e454fe9bdaee2a16aea47cf37e38081af45931e884e
5
5
  SHA512:
6
- metadata.gz: 9a8955692b0f1e9665c1449422d59ae40f3806c3be9e16f2a4de9a43a4a5e907ce1d0eafa0699fbdbf5b48cafb9b772cdbdfde12b45f1b9d0b95f819e50fb49c
7
- data.tar.gz: 5bceed442425fdcbf317aab144eb58f05414d857183fe81a47339504701e1086c8c88938672854705952e5907e2a314b5a9377ddcd480dbdd371a3f03035c2a4
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
- route_classes = ForestAdminRpcAgent::Routes.constants.reject { |route| route.to_s == 'BaseRoute' }
2
+ next if defined?(Rake) && Rake.respond_to?(:application) && Rake.application&.top_level_tasks&.any?
3
3
 
4
- route_classes.each do |route|
5
- route_class = ForestAdminRpcAgent::Routes.const_get(route)
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
@@ -1,3 +1,3 @@
1
1
  module ForestAdminRpcAgent
2
- VERSION = "1.13.4"
2
+ VERSION = "1.14.0"
3
3
  end
@@ -23,6 +23,7 @@ module ForestAdminRpcAgent
23
23
  setting :logger_level, default: 'info'
24
24
  setting :logger, default: nil
25
25
  setting :customize_error_message, default: nil
26
+ setting :disable_route_cache, default: false
26
27
 
27
28
  begin
28
29
  require 'thor'
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.13.4
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-06 00:00:00.000000000 Z
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