Class: RakeAudit::ExecutionRecorder
- Inherits:
-
Object
- Object
- RakeAudit::ExecutionRecorder
- Defined in:
- lib/rake_audit/execution_recorder.rb
Overview
Wraps a single Rake task execution to capture timing, success/failure, and any raised exception, then persists a TaskExecutionRecord via the configured adapter.
Design invariants:
-
The original task exception always propagates unchanged (re-raised).
-
Persistence happens in an
ensureblock so it runs on both success and failure paths. -
Adapter errors are logged and swallowed; they never affect the task result.
-
When no adapter is configured, saving is skipped entirely.
Instance Method Summary collapse
-
#initialize(task:, args: nil) ⇒ ExecutionRecorder
constructor
A new instance of ExecutionRecorder.
-
#record { ... } ⇒ Object
Execute the given block, capturing timing and outcome.
Constructor Details
#initialize(task:, args: nil) ⇒ ExecutionRecorder
Returns a new instance of ExecutionRecorder.
19 20 21 22 |
# File 'lib/rake_audit/execution_recorder.rb', line 19 def initialize(task:, args: nil) @task = task @args = args end |
Instance Method Details
#record { ... } ⇒ Object
Execute the given block, capturing timing and outcome.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rake_audit/execution_recorder.rb', line 29 def record started_at = now exception = nil begin yield rescue Exception => e # rubocop:disable Lint/RescueException exception = e raise ensure finished_at = now save_record(started_at: started_at, finished_at: finished_at, exception: exception) end end |