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
RateLimit, CircuitBreaker, Lock, and Idempotency when declared,
then Retry; output verification runs inside the lock lease and idempotency
claim when enabled), rollback on failure, result finalization, and teardown
(freeze + chain clear).
Signal propagation: work and the surrounding middleware/callback chain
both run inside catch(Signal::TAG), so success! / skip! / fail! /
throw! halt cleanly from anywhere. Raised Faults become echoed signals
(with the upstream result as :origin); other StandardErrors become
failed signals (with the exception as :cause). In strict mode,
execute! re-raises from ensure using 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.
39 40 41 42 |
# File 'lib/cmdx/runtime.rb', line 39 def initialize(task, strict: false) @task = task @strict = strict end |
Class Method Details
.execute(task, strict: false) ⇒ Result
Returns the finalized, frozen result.
31 32 33 |
# File 'lib/cmdx/runtime.rb', line 31 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.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cmdx/runtime.rb', line 50 def execute acquire_chain run_middlewares do Telemetry.emit(@task, :task_started, root: @root) run_deprecation run_lifecycle end finalize_result ensure run_teardown raise_signal! end |