MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeFailoverStorage

Function makeFailoverStorage

packages/cluster/test/Sharding.test.ts:1657–1709  ·  view source on GitHub ↗
(state: FailoverStorageState, clock: Clock.Clock)

Source from the content-addressed store, hash-verified

1655})
1656
1657const makeFailoverStorage = (state: FailoverStorageState, clock: Clock.Clock) =>
1658 RunnerStorage.RunnerStorage.of({
1659 getRunners: Effect.sync(() => {
1660 if (!state.runner) return []
1661 if (!state.assignSelf) return [[state.runner, false], [otherRunner, true]]
1662 return state.otherRunnerHealthy ? [[state.runner, true], [otherRunner, true]] : [[state.runner, true]]
1663 }),
1664 register: (runner) =>
1665 Effect.sync(() => {
1666 state.runner = runner
1667 return MachineId.make(1)
1668 }),
1669 unregister: () => Effect.void,
1670 setRunnerHealth: () => Effect.void,
1671 acquire: (_address, shardIds) =>
1672 Effect.sync(() => {
1673 const shards = globalThis.Array.from(shardIds)
1674 state.acquireCalls.push({
1675 shards,
1676 completedReleaseAlls: state.releaseAllCalls.filter((call) => call.completed).length
1677 })
1678 return shards
1679 }),
1680 refresh: (_address, shardIds) =>
1681 Effect.suspend(() => {
1682 const shards = globalThis.Array.from(shardIds)
1683 state.refreshCalls.push({
1684 at: clock.unsafeCurrentTimeMillis(),
1685 shards
1686 })
1687 return state.blackholed ? Effect.never : Effect.succeed(shards)
1688 }),
1689 release: (_address, shardId) =>
1690 Effect.suspend(() => {
1691 state.releaseCalls.push(shardId)
1692 if (state.releaseFailures > 0) {
1693 state.releaseFailures--
1694 return Effect.fail(new ClusterError.PersistenceError({ cause: "release failed" }))
1695 }
1696 return Effect.void
1697 }),
1698 releaseAll: () =>
1699 Effect.suspend(() => {
1700 const call = { completed: false }
1701 state.releaseAllCalls.push(call)
1702 return Effect.andThen(
1703 Effect.sleep(state.releaseAllDuration),
1704 Effect.sync(() => {
1705 call.completed = true
1706 })
1707 )
1708 })
1709 })
1710
1711const handoffShards = 4
1712const handoffShardIds = Array.makeBy(handoffShards, (i) => ShardIdModule.make("default", i + 1))

Callers 2

Sharding.test.tsFile · 0.85
makeTerminationShardingFunction · 0.85

Calls 6

syncMethod · 0.80
ofMethod · 0.65
makeMethod · 0.65
failMethod · 0.65
sleepMethod · 0.65

Tested by

no test coverage detected