Beethoven.Utils (Beethoven v0.2.3)

Module for generic utilities.

Summary

Functions

Performs a backoff wait to void race conditions in a distributed environment. (:rand.uniform(1 - max) + delta) * multiplier

The same as backoff/3 but shows the calling service's name in the verbose output.

Copies desired table to local node memory.

Gets an environmental variable from beethoven's application config

Retrieves roles from config and converts to map.

Check if Mnesia table exists

Toggles the monitoring status of all nodes in the cluster.

Toggles the monitoring status of another node in the cluster.

Fn to simplify calling named Processes on other nodes... and getting a call back.

Creates a map from a list of maps. First element of the map needs to be an atom. This same atom will be the key for the rest of the data in the map.

Runs a job within a synchronous transaction

Functions

backoff(max \\ 20, delta \\ 0, multiplier \\ 1)

@spec backoff(integer(), integer(), integer()) :: :ok

Performs a backoff wait to void race conditions in a distributed environment. (:rand.uniform(1 - max) + delta) * multiplier

backoff_n(name, max \\ 20, delta \\ 0, multiplier \\ 1)

@spec backoff_n(atom(), integer(), integer(), integer()) :: :ok

The same as backoff/3 but shows the calling service's name in the verbose output.

Performs a backoff wait to void race conditions in a distributed environment. (:rand.uniform(1 - max) + delta) * multiplier

copy_mnesia_table(table)

@spec copy_mnesia_table(atom()) :: :ok | :already_exists | {:error, any()}

Copies desired table to local node memory.

  • Table must already exist in the cluster.
  • If the table was initialized on this node, the table is already in memory.
  • If node successfully joined in the past, but power-cycled, rebooting will automatically grab the tables from the cluster.

get_app_env(envVar, default \\ nil)

Gets an environmental variable from beethoven's application config

get_role_config()

@spec get_role_config() :: map()

Retrieves roles from config and converts to map.

mnesia_table_exists?(table)

@spec mnesia_table_exists?(atom()) :: boolean()

Check if Mnesia table exists

monitor_all_nodes(mode)

@spec monitor_all_nodes(boolean()) :: :ok

Toggles the monitoring status of all nodes in the cluster.

monitor_node(nodeName, mode)

@spec monitor_node(node(), boolean()) :: :ok

Toggles the monitoring status of another node in the cluster.

remote_call(fun, host, timeout \\ 1000)

@spec remote_call((-> any()), node(), integer()) :: any() | {:error, :timeout}

Fn to simplify calling named Processes on other nodes... and getting a call back.

role_list_to_map(role_list)

Creates a map from a list of maps. First element of the map needs to be an atom. This same atom will be the key for the rest of the data in the map.

sync_run(fun)

@spec sync_run((-> :ok)) :: {:atomics, :ok} | {:error, any()}

Runs a job within a synchronous transaction