SqlRunnerStorage.ts
SqlRunnerStorage.ts overview
Section titled “SqlRunnerStorage.ts overview”Stores cluster runner registration and shard ownership in SQL.
The SQL-backed RunnerStorage records runners, health flags, machine ids,
and shard locks so multiple processes can coordinate which runner owns each
shard. This module creates the required runner and lock tables, supports an
optional table prefix, uses advisory locks for PostgreSQL and MySQL when
enabled, and provides constructors and layers for the storage service.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”constructors
Section titled “constructors”Creates a SQL-backed RunnerStorage implementation for registered runners and
shard locks, using the configured table prefix and advisory locks where
supported and enabled.
When to use
Use to create a SQL-backed RunnerStorage value directly when building
custom service or layer composition around the storage implementation.
Details
When prefix is omitted, make uses the cluster prefix, creating
cluster_runners and cluster_locks. PostgreSQL and MySQL use advisory
locks unless ShardingConfig.shardLockDisableAdvisory is enabled; other
dialects use rows in the locks table.
Gotchas
Changing prefix changes both generated table names, so runners using
different prefixes do not share registrations or shard locks.
See
layerfor the default SQL-backed storage layerlayerWithfor a SQL-backed storage layer with a custom table prefix
Signature
declare const make: (options: { readonly prefix?: string | undefined}) => Effect.Effect< { readonly register: (runner: Runner, healthy: boolean) => Effect.Effect<MachineId, PersistenceError> readonly unregister: (address: RunnerAddress) => Effect.Effect<void, PersistenceError> readonly getRunners: Effect.Effect<Array<readonly [runner: Runner, healthy: boolean]>, PersistenceError> readonly setRunnerHealth: (address: RunnerAddress, healthy: boolean) => Effect.Effect<void, PersistenceError> readonly acquire: ( address: RunnerAddress, shardIds: Iterable<ShardId.ShardId> ) => Effect.Effect<Array<ShardId.ShardId>, PersistenceError> readonly refresh: ( address: RunnerAddress, shardIds: Iterable<ShardId.ShardId> ) => Effect.Effect<Array<ShardId.ShardId>, PersistenceError> readonly release: (address: RunnerAddress, shardId: ShardId.ShardId) => Effect.Effect<void, PersistenceError> readonly releaseAll: (address: RunnerAddress) => Effect.Effect<void, PersistenceError> }, SqlError, Scope.Scope | SqlClient.SqlClient | ShardingConfig.ShardingConfig>Since v4.0.0
layers
Section titled “layers”Layer that provides SQL-backed RunnerStorage using the default table prefix.
Signature
declare const layer: Layer.Layer< RunnerStorage.RunnerStorage, SqlError, SqlClient.SqlClient | ShardingConfig.ShardingConfig>Since v4.0.0
layerWith
Section titled “layerWith”Layer that provides SQL-backed RunnerStorage using a custom table prefix.
Signature
declare const layerWith: (options: { readonly prefix?: string | undefined}) => Layer.Layer<RunnerStorage.RunnerStorage, SqlError, SqlClient.SqlClient | ShardingConfig.ShardingConfig>Since v4.0.0