Normandy.Cluster (normandy v1.1.1)

View Source

Optional convenience for wiring the distributed-session infra (Tier 2) into a host supervision tree. Returns child specs for:

  • the Horde registry (SessionRegistry.Horde, members: :auto),
  • the Horde supervisor (Turn.Supervisor.Horde, members: :auto),
  • the Turn.ResumeReaper (only when both :store and :template_provider are supplied — eager handoff needs them), and
  • an optional libcluster Cluster.Supervisor (only when :topologies is given AND libcluster is a dependency of the host app).

Cluster formation remains the host's choice — this is sugar, not a requirement. Normandy does NOT depend on libcluster; the Cluster.Supervisor spec is added only if the running system has it loaded (a runtime check), so hosts that wire their own clustering (or none) are unaffected.

Example (host application.ex)

children = [
  MyApp.Repo,
  {Normandy.Behaviours.AgentTemplate.Catalog, name: MyApp.AgentTemplates}
] ++
  Normandy.Cluster.child_specs(
    registry: MyApp.SessionRegistry,
    supervisor: MyApp.TurnSupervisor,
    store: {Normandy.Behaviours.SessionStore.Postgres, MyApp.Repo},
    template_provider: {Normandy.Behaviours.AgentTemplate.Catalog, MyApp.AgentTemplates},
    topologies: Application.get_env(:libcluster, :topologies, [])
  )

Supervisor.start_link(children, strategy: :one_for_one)

Summary

Functions

Build the distributed-session child specs. Required: :registry, :supervisor (names/atoms). Optional: :store + :template_provider (enable the reaper), :topologies (enable libcluster if loaded).

Child specs for the Redis combo (Redis registry + Redis store + local supervisor + reaper) — Redis as the single distributed dependency. Required: :redix (keyword for the Redix connection, must include :name), :namespace, :registry (owner name), :supervisor (local supervisor name). Optional: :template_provider (enables the ResumeReaper for eager handoff). Cross-node routing still uses Erlang distribution.

Create the Mnesia store tables (host setup, not a child spec). Thin pass-through to SessionStore.Mnesia.create_tables/1 — call once at boot before serving sessions. See that function for opts (:entries, :sessions, :copies, :nodes).

Functions

child_specs(opts)

@spec child_specs(keyword()) :: [
  Supervisor.child_spec() | :supervisor.child_spec() | map()
]

Build the distributed-session child specs. Required: :registry, :supervisor (names/atoms). Optional: :store + :template_provider (enable the reaper), :topologies (enable libcluster if loaded).

redis_child_specs(opts)

@spec redis_child_specs(keyword()) :: [Supervisor.child_spec() | map()]

Child specs for the Redis combo (Redis registry + Redis store + local supervisor + reaper) — Redis as the single distributed dependency. Required: :redix (keyword for the Redix connection, must include :name), :namespace, :registry (owner name), :supervisor (local supervisor name). Optional: :template_provider (enables the ResumeReaper for eager handoff). Cross-node routing still uses Erlang distribution.

setup_mnesia_store!(opts)

@spec setup_mnesia_store!(keyword()) :: :ok

Create the Mnesia store tables (host setup, not a child spec). Thin pass-through to SessionStore.Mnesia.create_tables/1 — call once at boot before serving sessions. See that function for opts (:entries, :sessions, :copies, :nodes).