SuperWorker.Supervisor.Validator (SuperWorker v0.3.6)
View SourceUtility functions for SuperWorker.Supervisor.
This module provides common utility functions used across the supervisor implementation, including:
- Option normalization and validation
- API call helpers
- Hashing and partitioning utilities
- Process information helpers
Summary
Functions
Checks that the value of a key in options passes a validation function.
Computes a hash-based order for partitioning data.
Converts a keyword option shorthand to a full keyword tuple.
Types
@type timeout_ms() :: non_neg_integer() | :infinity
Functions
@spec check_type(map(), atom(), (any() -> boolean())) :: api_result()
Checks that the value of a key in options passes a validation function.
Examples
iex> check_type(%{count: 5}, :count, &is_integer/1)
{:ok, %{count: 5}}
iex> check_type(%{count: "five"}, :count, &is_integer/1)
{:error, :invalid_type}
@spec get_hash_order(term(), pos_integer()) :: non_neg_integer()
Computes a hash-based order for partitioning data.
Uses Erlang's phash2 for consistent hashing across the cluster.
Examples
iex> order = get_hash_order("my_data", 10)
iex> order >= 0 and order < 10
true
Converts a keyword option shorthand to a full keyword tuple.
Used for converting shorthand like :group to {:type, :group}.
@spec normalize_options([keyword() | atom()], [atom()]) :: api_result()