SuperWorker.Supervisor.Utils (SuperWorker v0.3.6)
View SourceUtility functions for SuperWorker.Supervisor.
This module provides common utility functions used across the supervisor implementation, including:
- Hashing and partitioning utilities
- Process information helpers
Summary
Functions
Counts the number of messages in a process's message queue.
Returns the number of online schedulers in the system.
Computes a hash-based order for partitioning data.
Generates a cryptographically secure random ID.
Functions
@spec count_msgs(pid()) :: non_neg_integer()
Counts the number of messages in a process's message queue.
Returns 0 if the process is not alive.
@spec get_default_schedulers() :: pos_integer()
Returns the number of online schedulers in the system.
This is typically used as the default number of partitions.
@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
@spec random_id() :: String.t()
Generates a cryptographically secure random ID.
Returns a 32-character hexadecimal string.
Examples
iex> id = random_id()
iex> String.length(id)
32