Module: CMDx::Middlewares::Runtime

Extended by:
Runtime
Included in:
Runtime
Defined in:
lib/cmdx/middlewares/runtime.rb

Overview

Middleware for measuring task execution runtime.

The Runtime middleware provides performance monitoring by measuring the execution time of tasks using monotonic clock for accuracy. It stores runtime measurements in task result metadata for analysis.

Instance Method Summary collapse

Instance Method Details

#call(task, **options) { ... } ⇒ Object

Middleware entry point that measures task execution runtime.

Evaluates the condition from options and measures execution time if enabled. Uses monotonic clock for precise timing measurements and stores the result in task metadata.

Examples:

Basic usage with automatic runtime measurement

Runtime.call(task, &block)

Conditional runtime measurement

Runtime.call(task, if: :enable_profiling, &block)

Disable runtime measurement

Runtime.call(task, unless: :skip_profiling, &block)

Parameters:

  • task (Task)

    The task being executed

  • options (Hash)

    Configuration options for runtime measurement

Options Hash (**options):

  • :if (Symbol, Proc, Object, nil)

    Condition to enable runtime measurement

  • :unless (Symbol, Proc, Object, nil)

    Condition to disable runtime measurement

Yields:

  • The task execution block

Returns:

  • (Object)

    The result of task execution



37
38
39
40
41
42
43
44
# File 'lib/cmdx/middlewares/runtime.rb', line 37

def call(task, **options)
  return yield unless Utils::Condition.evaluate(task, options)

  now = monotonic_time
  result = yield
  task.result.[:runtime] = monotonic_time - now
  result
end