Module: Hecks::Runtime::Registry::SagaPersistence

Included in:
Hecks::Runtime::Registry
Defined in:
lib/hecks/runtime/registry/saga_persistence.rb

Overview

SAGA PERSISTENCE — no new DSL verb, no new world setting. Whatever adapter a domain's own aggregates already use for durability, its sagas use the same one, automatically: three OPTIONAL adapter methods (save_saga/delete_saga/each_saga), respond_to?-checked the same way Ports::Persistence::AppendOnly already treats an adapter's own optional methods (find/all/count/reset!/events/record_event).

Instance Method Summary collapse

Instance Method Details

#rehydrate_sagas!Object

WALKS EVERY LOADED DOMAIN, repopulating saga_instances from whatever saga_persistence(domain) resolves to — a real store for a domain whose adapter answers the capability, each_saga yielding real rows; NULL_SAGA_STORE's own each_saga for everything else, which never yields at all, so this needs no respond_to? branch of its own — the SAME reason every other call site in this capability never needs one. Called once at boot (Loader.boot, between verify! and dispatcher construction) — a process that's been running has no reason to re-walk its own already-current saga_instances.



37
38
39
40
41
42
43
44
# File 'lib/hecks/runtime/registry/saga_persistence.rb', line 37

def rehydrate_sagas!
  @hecksagons.each_key do |domain|
    saga_persistence(domain).each_saga do |process_manager, correlation, state, memory|
      @saga_instances[process_manager][correlation] = { state: state, memory: memory }
    end
  end
  self
end

#saga_persistence(domain) ⇒ Object

Resolved and memoized per domain — the FIRST real aggregate declared in the domain's own bluebook is the resolution anchor. Ports::Persistence::BindingPolicy.resolve for that aggregate already falls back to a domain-level default bind (§0's Hecksagon#bind_for) before falling back to Memory, so this needs no separate "was a default declared" branch of its own — whatever adapter that anchor resolves to already IS the domain's own default in the normal case (every aggregate shares one adapter), and is the honest, documented fallback for the rarer domain genuinely split across more than one local adapter with no default declared.



23
24
25
# File 'lib/hecks/runtime/registry/saga_persistence.rb', line 23

def saga_persistence(domain)
  (@saga_persistence ||= {})[domain.to_s] ||= resolve_saga_persistence(domain.to_s)
end