github Effect-TS/effect @effect/cluster@0.38.0

latest releases: @effect/ai-anthropic@0.16.1, @effect/cluster@0.48.3, @effect/workflow@0.9.3...
3 months ago

Minor Changes

  • #4969 3086405 Thanks @tim-smart! - add shard groups, to allow entities to target specific runners

    If you need to migrate an existing cluster, you can run the following PostgreSQL queries:

    ALTER TABLE cluster_messages
      ALTER COLUMN shard_id TYPE VARCHAR(50) USING format('default:%s', shard_id);
    
    ALTER TABLE cluster_shards
      ALTER COLUMN shard_id TYPE VARCHAR(50) USING format('default:%s', shard_id);
    
    ALTER TABLE cluster_locks
      ALTER COLUMN shard_id TYPE VARCHAR(50) USING format('default:%s', shard_id);

    To use shard groups, you can add a ShardGroup annotation when creating an
    entity. You can then assign shard groups to specific runners in your layer
    setup:

    import { ClusterSchema, Entity } from "@effect/cluster"
    import {
      NodeClusterRunnerSocket,
      NodeClusterShardManagerSocket
    } from "@effect/platform-node"
    import { Rpc } from "@effect/rpc"
    import { Schema } from "effect"
    
    const Counter = Entity.make("Counter", [
      Rpc.make("Increment", {
        payload: { id: Schema.String, amount: Schema.Number },
        primaryKey: ({ id }) => id,
        success: Schema.Number
      })
    ])
      .annotate(ClusterSchema.ShardGroup, (_entityId) => "someGroupName")
      .annotateRpcs(ClusterSchema.Persisted, true)
    
    // Assign the shard group to a specific runner in your layer setup.
    //
    // Make sure to include the "default" shard group, if you want to run entities
    // without a specific group.
    //
    NodeClusterRunnerSocket.layer({
      shardingConfig: {
        shardGroups: ["default", "someGroupName"]
      }
    })

Patch Changes

Don't miss a new effect release

NewReleases is sending notifications on new releases.