Class: CMDx::Runtime

Inherits:
Object
  • Object
show all
Defined in:
lib/cmdx/runtime.rb

Overview

Note:

Always used via the class method; never new Runtime manually.

Orchestrates a task’s full lifecycle: chain acquisition, middlewares, telemetry, deprecation, callbacks, input resolution, ‘work` (wrapped in retry), output verification, rollback on failure, result finalization, and teardown (freeze + chain clear).

Signal propagation: Runtime wraps ‘work` in `catch(Signal::TAG)` so `success!` / `skip!` / `fail!` / `throw!` break out cleanly. Raised Faults are converted to echoed signals (carrying the upstream failed result as `:origin`); other `StandardError`s become failed signals with the exception as `:cause`. `execute!` (strict mode) re-raises on failure after the result is finalized, raising a Fault built from the deepest originating result so `fault.task` points at the leaf that failed.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, strict: false) ⇒ Runtime

Returns a new instance of Runtime.

Parameters:

  • task (Task)
  • strict (Boolean) (defaults to: false)


36
37
38
39
# File 'lib/cmdx/runtime.rb', line 36

def initialize(task, strict: false)
  @task   = task
  @strict = strict
end

Class Method Details

.execute(task, strict: false) ⇒ Result

Returns the finalized, frozen result.

Parameters:

  • task (Task)
  • strict (Boolean) (defaults to: false)

    when true, re-raise on failure (‘execute!` semantics)

Returns:

  • (Result)

    the finalized, frozen result

Raises:

  • (Fault, StandardError)

    only when ‘strict: true` and the task failed



28
29
30
# File 'lib/cmdx/runtime.rb', line 28

def execute(task, strict: false)
  new(task, strict:).execute
end

Instance Method Details

#executeResult

Runs the full lifecycle. Teardown runs in ‘ensure`, guaranteeing the task’s context/errors get frozen and the fiber chain is cleared even when strict mode re-raises.

Returns:

Raises:

  • (Fault, StandardError)

    under strict mode on failure



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cmdx/runtime.rb', line 47

def execute
  acquire_chain

  run_middlewares do
    emit_telemetry(:task_started)
    run_deprecation
    run_lifecycle
    finalize_result
    raise_signal! if @strict
  end

  @result
ensure
  run_teardown
end