Class: CDC::Parallel::Runtime
- Inherits:
-
Object
- Object
- CDC::Parallel::Runtime
- Defined in:
- lib/cdc/parallel/runtime.rb
Overview
Runtime is an execution facade, not a source adapter. It expects
work that has already been normalized into cdc-core primitives.
High-level Ractor runtime facade for cdc-core processors.
Runtime is the primary public entry point for applications that want to
execute normalized CDC work items with cdc-parallel. It wires together a
ProcessorPool, a TransactionPool, and a Router so callers can submit
either a single CDC::Core::ChangeEvent or a
CDC::Core::TransactionEnvelope through one object.
Use this class when you want the default cdc-parallel behavior:
- validate that the processor declared
ractor_safe! - boot a fixed set of worker Ractors
- route events and transaction envelopes to the right pool
- return
CDC::Core::ProcessorResultobjects - shut down all worker resources together
Instance Method Summary collapse
-
#initialize(processor:, size: Etc.nprocessors, timeout: nil, supervision: true, max_respawns: 3, respawn_window: 60, respawn_cooldown: 5) ⇒ void
constructor
Create a runtime with event and transaction pools.
-
#process(item) ⇒ CDC::Core::ProcessorResult
Process a supported normalized CDC work item.
-
#process_transaction(transaction) ⇒ CDC::Core::ProcessorResult
Process a transaction envelope.
-
#shutdown ⇒ void
Shut down all runtime resources.
Constructor Details
#initialize(processor:, size: Etc.nprocessors, timeout: nil, supervision: true, max_respawns: 3, respawn_window: 60, respawn_cooldown: 5) ⇒ void
Create a runtime with event and transaction pools.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cdc/parallel/runtime.rb', line 65 def initialize( processor:, size: Etc.nprocessors, timeout: nil, supervision: true, max_respawns: 3, respawn_window: 60, respawn_cooldown: 5 ) @processor = processor @processor.start = ( processor:, size:, timeout:, supervision:, max_respawns:, respawn_window:, respawn_cooldown: ) @processor_pool = ProcessorPool.new(**) @transaction_pool = TransactionPool.new(**) @router = Router.new(processor_pool: @processor_pool, transaction_pool: @transaction_pool) @shutdown = false end |
Instance Method Details
#process(item) ⇒ CDC::Core::ProcessorResult
Process a supported normalized CDC work item.
Supported items are CDC::Core::ChangeEvent and
CDC::Core::TransactionEnvelope. Unsupported objects raise
UnsupportedWorkItemError from the router.
101 102 103 104 105 |
# File 'lib/cdc/parallel/runtime.rb', line 101 def process(item) raise ShutdownError, "runtime has been shut down" if @shutdown @router.process(item) end |
#process_transaction(transaction) ⇒ CDC::Core::ProcessorResult
Process a transaction envelope.
This method is a readability alias for transaction-oriented call sites. It delegates to #process, so it has the same validation, shutdown, and result behavior.
115 116 117 |
# File 'lib/cdc/parallel/runtime.rb', line 115 def process_transaction(transaction) process(transaction) end |
#shutdown ⇒ void
This method returns an undefined value.
Shut down all runtime resources.
Shutdown is idempotent and cascades to the internal event and transaction
pools. The processor's flush and stop lifecycle hooks are called once
after all pools have been drained. After shutdown, #process raises
ShutdownError.
127 128 129 130 131 132 133 134 135 |
# File 'lib/cdc/parallel/runtime.rb', line 127 def shutdown return if @shutdown @shutdown = true @processor_pool.shutdown @transaction_pool.shutdown @processor.flush @processor.stop end |