Defines the configuration for a function that can be called through the API.
This struct holds all the necessary information to route, validate, and execute a function call based on an incoming request.
Retry
The retry field configures retry behavior when request execution fails
(returns {:error, _} or {:error, _, _}).
Possible values:
nil- No retry (default, backward compatible)- A positive number (e.g.,
3) - Equivalent to{:all_nodes, 3}. Retry across all available nodes. {:same_node, positive_number}(e.g.,{:same_node, 2}) - Retry on the same node(s) that were originally selected by thechoose_node_modestrategy. Useful when the failure might be transient.{:all_nodes, positive_number}(e.g.,{:all_nodes, 3}) - Retry across all available nodes in the cluster. Useful when a node might be down.
For nodes: :local, both :same_node and :all_nodes retry on the same
local machine since there's only one node.
Use normalize_retry/1 to convert a raw config value to the standard tuple
format. Zero, negative numbers, strings, and other formats are invalid.
Security Considerations
- MFA tuples are validated to ensure modules are loaded and functions exist
- Node lists are validated to prevent routing to invalid destinations
- Permission modes are checked against available request fields
- Timeout values are bounded to prevent resource exhaustion
Summary
Functions
Checks if the request has the necessary permissions to be executed.
Validates and converts the request arguments based on the arg_types and arg_orders configuration.
Selects a target node for the request based on the choose_node_mode strategy.
Checks if the service is configured to run locally.
Normalizes the retry configuration into a standard tuple format.
Validates the function configuration.
Validates the function configuration and returns detailed error information.
Returns the version of the function configuration. If the version is not set or missing (for backward compatibility with old configs), returns "0.0.0" as default.
Types
@type t() :: %PhoenixGenApi.Structs.FunConfig{ after_execute: {module(), atom()} | {module(), atom(), args :: list()} | nil, arg_orders: [String.t()] | :map, arg_types: map() | nil, before_execute: {module(), atom()} | {module(), atom(), args :: list()} | nil, check_permission: false | :any_authenticated | {:arg, String.t()} | {:role, list()}, choose_node_mode: :random | :hash | {:hash, String.t()} | :round_robin, disabled: boolean(), mfa: {module(), function(), args :: list()}, nodes: [atom()] | {module(), function(), args :: list()} | :local, permission_callback: {module(), atom(), args :: list()} | nil, request_info: boolean(), request_type: String.t(), response_type: :sync | :async | :stream | :none, retry: {:same_node, number()} | {:all_nodes, number()} | number() | nil, service: atom() | String.t(), timeout: integer() | :infinity, version: String.t() }
Functions
Checks if the request has the necessary permissions to be executed.
Validates and converts the request arguments based on the arg_types and arg_orders configuration.
Selects a target node for the request based on the choose_node_mode strategy.
Checks if the service is configured to run locally.
@spec normalize_retry( nil | number() | {:same_node, number()} | {:all_nodes, number()} ) :: nil | {:same_node, pos_integer()} | {:all_nodes, pos_integer()}
Normalizes the retry configuration into a standard tuple format.
nilremainsnil(no retry)- A number
nis converted to{:all_nodes, n} {:same_node, n}and{:all_nodes, n}are returned as-is
Examples
iex> FunConfig.normalize_retry(nil)
nil
iex> FunConfig.normalize_retry(3)
{:all_nodes, 3}
iex> FunConfig.normalize_retry({:same_node, 2})
{:same_node, 2}
iex> FunConfig.normalize_retry({:all_nodes, 5})
{:all_nodes, 5}
Validates the function configuration.
Returns true if all configuration fields are valid, false otherwise.
Logs detailed error messages for each invalid field.
Validation Checks
request_typemust be a non-empty stringservicemust not be nilnodesmust be a valid list, MFA tuple, or:localchoose_node_modemust be a recognized strategytimeoutmust be a positive integer or:infinitymfamust be a valid{module, function, args}tuplearg_typesandarg_ordersmust be consistentresponse_typemust be one of:sync,:async,:stream, or:nonecheck_permissionmust be a valid permission moderequest_infomust be a boolean
Validates the function configuration and returns detailed error information.
Returns {:ok, config} if valid, or {:error, [error_messages]} if invalid.
Returns the version of the function configuration. If the version is not set or missing (for backward compatibility with old configs), returns "0.0.0" as default.