Class: RailsAiBridge::Introspector::TimedRunner
- Inherits:
-
Object
- Object
- RailsAiBridge::Introspector::TimedRunner
- Defined in:
- lib/rails_ai_bridge/introspector/timed_runner.rb
Overview
Executes a single introspector class and measures how long it takes.
This is a pure value-object service: it has no state of its own and is not responsible for thread management, error aggregation, or configuration. It does one thing — run an introspector and tell you how long it took.
The result hash uses two keys:
- +:result+ — the raw return value of the introspector, or +{ error: message }+ when the introspector raises.
- +:duration_ms+ — wall-clock time of the introspector call in milliseconds, as a +Float+. Available even on error so callers can diagnose slow-then-failing introspectors.
Class Method Summary collapse
-
.call(klass, app) ⇒ Hash{Symbol => Object}
Instantiates +klass+ with +app+ and calls it, measuring elapsed time.
Class Method Details
.call(klass, app) ⇒ Hash{Symbol => Object}
Instantiates +klass+ with +app+ and calls it, measuring elapsed time.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rails_ai_bridge/introspector/timed_runner.rb', line 30 def self.call(klass, app) result = nil caught = nil started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) begin result = klass.new(app).call rescue StandardError => error caught = error end duration_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - started_at) * 1000.0).round(2) payload = caught ? { error: caught. } : result { result: payload, duration_ms: duration_ms } end |