Skip to content

Commit 8aefcde

Browse files
committed
Improve logging and queue handling in iro-runtime plugin system
Added detailed debug logs to improve traceability of plugin actions such as registration, replugging, and deferred promises. Enhanced queue handling with additional logging for unresolved promises. This improves visibility into the plugin lifecycle and ensures better debugging of runtime behaviors. No breaking changes introduced.
1 parent 3d57f74 commit 8aefcde

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

iro-runtime-rb/lib/iro/runtime/plugin/dsl.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ def enqueue(**, &)
1919

2020
def install
2121
@queue.resolve.then do |queue|
22-
queue.reject(&:resolved?).each { |future| Runtime.queue.push(future) }
22+
remaining = queue.reject(&:resolved?)
23+
Iro.logger.debug('runtime') { "installed #{@plugin.name} with #{remaining.size} unresolved promises" }
24+
25+
remaining.each { |future| Runtime.queue.push(future) }
2326
end
2427
end
2528
end

iro-runtime-rb/lib/iro/runtime/plugin/dsl/behavior.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,25 @@ def initialize(manager, &block)
1212
end
1313

1414
def enhance_module(module_name, &enhancement)
15+
Iro.logger.debug('runtime') { "deferring enhancement of #{module_name}..." }
16+
1517
on_load(module_name) do
18+
Iro.logger.debug('runtime') { "#{@manager.plugin.name} enhancing #{module_name}..." }
1619
ModuleEnhancer.new(Runtime.constant.resolve(module_name), &enhancement)
20+
Iro.logger.debug('runtime') { "#{@manager.plugin.name} enhanced #{module_name}" }
1721
end
1822
end
1923

20-
def on_any(event_type = :ANY, **options, &)
24+
def on_any(event_type = :ANY, log: true, **options, &)
2125
predicate = lambda do |data|
2226
event_type == :ANY || (data[:type] == event_type &&
2327
(options.key?(:if) ? options[:if].call(data) : true))
2428
end
2529

30+
if log
31+
Iro.logger.debug('runtime') { "#{@manager.plugin.name} deferring promise pending #{event_type} event" }
32+
end
33+
2634
@manager.enqueue(if: predicate, **options.except(:if), &)
2735
end
2836

@@ -32,7 +40,9 @@ def on_load(constant_name, **options, &)
3240
(options.key?(:if) ? options[:if].call(data) : true)
3341
end
3442

35-
on_any(if: predicate, **options.except(:if), &)
43+
Iro.logger.debug('runtime') { "#{@manager.plugin.name} deferring promise pending load of #{constant_name}" }
44+
45+
on_any(if: predicate, log: false, **options.except(:if), &)
3646
end
3747

3848
def on_plugin(plugin_name, **options, &)
@@ -41,7 +51,11 @@ def on_plugin(plugin_name, **options, &)
4151
(options.key?(:if) ? options[:if].call(data) : true)
4252
end
4353

44-
on_any(if: predicate, **options.except(:if), &)
54+
Iro.logger.debug('runtime') do
55+
"#{@manager.plugin.name} deferring promise pending plugin registration of #{plugin_name}"
56+
end
57+
58+
on_any(if: predicate, log: false, **options.except(:if), &)
4559
end
4660

4761
def on_unload(constant_name, **options, &)
@@ -50,7 +64,11 @@ def on_unload(constant_name, **options, &)
5064
(options.key?(:if) ? options[:if].call(data) : true)
5165
end
5266

53-
on_any(:constant_unloaded, if: predicate, **options.except(:if), &)
67+
Iro.logger.debug('runtime') do
68+
"#{@manager.plugin.name} deferring promise pending unload of #{constant_name}"
69+
end
70+
71+
on_any(:constant_unloaded, log: false, if: predicate, **options.except(:if), &)
5472
end
5573
end
5674
end

iro-runtime-rb/lib/iro/runtime/plugin/registry.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ def handle_existing_plugin(name, &)
2222
end
2323

2424
dsl.install
25+
26+
Iro.logger.debug('runtime') { "plugin #{name} repluged" }
27+
Runtime.queue.resolve(type: :plugin_repluged, name:, plugin:)
28+
2529
[name, plugin]
2630
end
2731

2832
def register_new_plugin(name, root_path = nil, &)
2933
raise ArgumentError, '`root_path` is required for initial registration' unless root_path
3034

31-
Iro.logger.debug('runtime') { "registering plugin #{name}" }
35+
Iro.logger.debug('runtime') { "registering plugin #{name}..." }
3236
plugin = Plugin.new(name:, root_path:)
3337

3438
dsl = @mutex.synchronize do
@@ -38,6 +42,10 @@ def register_new_plugin(name, root_path = nil, &)
3842
end
3943

4044
dsl.install
45+
46+
Iro.logger.debug('runtime') { "plugin #{name} registered" }
47+
Runtime.queue.resolve(type: :plugin_registered, name:, plugin:)
48+
4149
[name, plugin]
4250
end
4351
end

0 commit comments

Comments
 (0)