Class: RakeAudit::ExecutionRecorder

Inherits:
Object
  • Object
show all
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 ensure block 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

Constructor Details

#initialize(task:, args: nil) ⇒ ExecutionRecorder

Returns a new instance of ExecutionRecorder.

Parameters:

  • task (#name)

    the Rake task being executed.

  • args (Object, nil) (defaults to: nil)

    arguments passed to the task.



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.

Yields:

  • runs the wrapped task body (typically super from the patch).

Returns:

  • (Object)

    the block’s return value on success.

Raises:

  • (Exception)

    re-raises whatever the block raised, unchanged.



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