Class: WhittakerTech::Aeon::Forker
- Inherits:
-
Object
- Object
- WhittakerTech::Aeon::Forker
- Defined in:
- app/services/whittaker_tech/aeon/forker.rb
Overview
Stateless service that performs forward-only timeline forking. Closes the current Allocation at a pivot point, creates a successor with lineage, set-based invalidates future Occurrence rows, and inline-projects the new allocation.
Two modes: - Fork future — +pivot > valid_from+: past occurrences are preserved, only future ones are invalidated. - Fork all — +pivot == valid_from+: every occurrence is invalidated and the allocation is fully replaced.
Class Method Summary collapse
-
.call(allocation_id:, pivot:, **new_attrs) ⇒ Allocation
The newly created successor.
Instance Method Summary collapse
-
#call ⇒ Allocation
Executes the fork within a serialised transaction.
-
#initialize(allocation_id:, pivot:, new_attrs:) ⇒ Forker
constructor
A new instance of Forker.
Constructor Details
#initialize(allocation_id:, pivot:, new_attrs:) ⇒ Forker
Returns a new instance of Forker.
33 34 35 36 37 |
# File 'app/services/whittaker_tech/aeon/forker.rb', line 33 def initialize(allocation_id:, pivot:, new_attrs:) @allocation_id = allocation_id @pivot = pivot @new_attrs = new_attrs end |
Class Method Details
.call(allocation_id:, pivot:, **new_attrs) ⇒ Allocation
Returns the newly created successor.
26 27 28 |
# File 'app/services/whittaker_tech/aeon/forker.rb', line 26 def self.call(allocation_id:, pivot:, **new_attrs) new(allocation_id: allocation_id, pivot: pivot, new_attrs: new_attrs).call end |
Instance Method Details
#call ⇒ Allocation
Executes the fork within a serialised transaction.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/services/whittaker_tech/aeon/forker.rb', line 42 def call Allocation.transaction do Allocation.connection.execute("SET LOCAL aeon.bypass_guard = 'true'") old_allocation = lock_allocation! validate_pivot!(old_allocation) close_allocation!(old_allocation) new_allocation = create_successor!(old_allocation) invalidate_future_occurrences!(old_allocation, new_allocation) project_successor!(new_allocation) new_allocation end end |