GitHub

sharding_config

API reference for sharding_config.

How a runner shards entities (Effect's ShardingConfig).

DEFAULTS holds Effect's defaults; layer(dataclasses.replace(DEFAULTS, shards_per_group=30)) provides a variation, and config / layer_from_env read one (HOST, PORT, SHARDS_PER_GROUP, ... in the environment). Durations are Duration values. "unbounded" for the mailbox capacity and resident entities is only available in code.

Values

AttributeTypeDescription
DEFAULTSShardingConfigService

Effect's defaults.

layer_defaultslayer_.Layer[ShardingConfig]

ShardingConfig with every setting at its default (DEFAULTS).

configConfig[ShardingConfigService]

The settings read from the current config provider, Effect's defaults for what is absent. Keys are camelCase (shardsPerGroup).

Types

TypeDefinitionDescription
Unboundedtype Unbounded = Literal['unbounded']

Classes

Functions

layer

layer(settings=DEFAULTS) -> layer_.Layer[ShardingConfig]
ParameterTypeDescription
settingsShardingConfigService = DEFAULTS

Returns layer_.Layer[ShardingConfig]

def layer(settings: ShardingConfigService = DEFAULTS) -> layer_.Layer[ShardingConfig]:
    return layer_.succeed(ShardingConfig, settings)

layer_from_env

layer_from_env(update=None) -> layer_.Layer[ShardingConfig, ConfigError]

The settings read from the environment in CONSTANT_CASE (SHARDS_PER_GROUP), then passed through update.

ParameterTypeDescription
updateCallable[[ShardingConfigService], ShardingConfigService] | None = None

Returns layer_.Layer[ShardingConfig, ConfigError]

def layer_from_env(
    update: Callable[[ShardingConfigService], ShardingConfigService] | None = None,
) -> layer_.Layer[ShardingConfig, ConfigError]:
    """The settings read from the environment in CONSTANT_CASE
    (``SHARDS_PER_GROUP``), then passed through ``update``."""
    read = config.parse(from_env().constant_case())
    return layer_.effect(ShardingConfig, read if update is None else read.map(update))

shard_group_config

shard_group_config(settings) -> ShardGroups

The available groups, and those of them this runner is assigned.

ParameterTypeDescription
settingsShardingConfigService

Returns ShardGroups

def shard_group_config(settings: ShardingConfigService) -> ShardGroups:
    """The available groups, and those of them this runner is assigned."""
    available = tuple(sorted(set(settings.available_shard_groups)))
    assigned = tuple(g for g in available if g in settings.assigned_shard_groups)
    return ShardGroups(available, assigned)