Skip to content

Cluster.layerObjectHost reference

Source: packages/effect-cluster/src/ObjectHost.ts Kind: Layer · Provides: ObjectHost

Objects on Effect Cluster. Every class declared on it is held by one entity, name: the object a-1 of the class Bank.AccountAggregate is the entity id Bank.AccountAggregate/a-1, on whichever runner holds its shard. Its storage is rows of the cluster’s Postgres, and its alarm a persisted message delivered when it is due.

Built in a caller (a container, a Lambda, a Worker), the Layer deploys that entity to pool and reaches it through the pool’s gateway. The pool’s runners load the Layer built on this one from main, and there the same Layer holds the entity.

It is the entrypoint of everything built on objects: provide it once, to the Layer the module exports as its default. DomainCluster.layerEntities() puts a Domain model on it, and AI.layerObjects a process’s sessions.

import * as AI from "@alchemy.run/ai";
import * as DomainCluster from "@alchemy.run/domain/EffectCluster";
import * as Cluster from "@alchemy.run/effect-cluster";
import * as ClusterDocker from "@alchemy.run/effect-cluster/Docker";
import * as Layer from "effect/Layer";
import { Harness } from "./Harness.ts";
import { Board, IssueWorkLive } from "./Board.model.ts";
import { TriageLive } from "./Triage.process.ts";
export const Database = ClusterDocker.Database("Cluster");
const Default = ClusterDocker.SwarmPool("Default").pipe(Layer.provide(Database));
const BoardLive = Board.layer(IssueWorkLive).pipe(Layer.provide(DomainCluster.layerEntities()));
const TriageSessions = AI.layerObjects(
TriageLive.pipe(Layer.provide(Layer.mergeAll(Harness, BoardLive))),
);
export default BoardLive.pipe(
Layer.provideMerge(TriageSessions),
Layer.provide(Cluster.layerObjectHost("App", { main: import.meta.url, pool: Default })),
);