hecate_om_store (hecate_om v0.3.1)

View Source

Canonical reckon-db + evoq wiring helper for hecate-services.

Encapsulates the "start a store, wait for it, start the per-store evoq subscription" pattern documented as MANDATORY in hecate-social/hecate-corpus/skills/ANTIPATTERNS_EVENT_SOURCING.md.

Services don't call this module directly — hecate_om:boot/1 dispatches here when the service module exports the optional store_id/0 + data_dir/0 callbacks from hecate_om_service.

The sys.config for any service that uses this helper MUST also set evoq's adapter to reckon_evoq_adapter:

{evoq, [ {event_store_adapter, reckon_evoq_adapter}, {subscription_adapter, reckon_evoq_adapter}, {store_id, my_service_store}, %% fallback for dispatch {consistency, eventual} ]}

Without that block, evoq crashes on first dispatch with {not_configured, event_store_adapter}. hecate_om can't inject it at runtime because evoq starts as a release-boot application before any service's start/2 runs.

Summary

Functions

One-call wiring: ensure the store + the subscription. Called by hecate_om:boot/1 when the service module declares store_id/0 and data_dir/0.

Idempotent. Starts a single-mode reckon_db_store at <DataDir>/<StoreId>/ and waits for it to register.

Start the per-store evoq subscription. Idempotent.

Block until the store is registered with reckon_db, or the deadline passes.

Functions

ensure(StoreId, DataDir)

-spec ensure(atom(), file:filename_all()) -> ok | {error, term()}.

One-call wiring: ensure the store + the subscription. Called by hecate_om:boot/1 when the service module declares store_id/0 and data_dir/0.

ensure_store(StoreId, DataDir)

-spec ensure_store(atom(), file:filename_all()) -> ok | {error, term()}.

Idempotent. Starts a single-mode reckon_db_store at <DataDir>/<StoreId>/ and waits for it to register.

ensure_subscription(StoreId)

-spec ensure_subscription(atom()) -> ok | {error, term()}.

Start the per-store evoq subscription. Idempotent.

wait_for_store(StoreId, TimeoutMs)

-spec wait_for_store(atom(), pos_integer()) -> ok | {error, term()}.

Block until the store is registered with reckon_db, or the deadline passes.