Class: CMDx::Runtime
- Inherits:
-
Object
- Object
- CMDx::Runtime
- Defined in:
- lib/cmdx/runtime.rb
Overview
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
-
.execute(task, strict: false) ⇒ Result
The finalized, frozen result.
Instance Method Summary collapse
-
#execute ⇒ Result
Runs the full lifecycle.
-
#initialize(task, strict: false) ⇒ Runtime
constructor
A new instance of Runtime.
Constructor Details
#initialize(task, strict: false) ⇒ Runtime
Returns a new instance of Runtime.
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.
28 29 30 |
# File 'lib/cmdx/runtime.rb', line 28 def execute(task, strict: false) new(task, strict:).execute end |
Instance Method Details
#execute ⇒ Result
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.
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 |