SuperWorker.ConfigLoader.Parser (SuperWorker v0.3.6)
View SourceParses and validates supervisor configurations from the application environment.
This module takes raw configuration keyword lists and transforms them into validated structures that can be used by the Bootstrap module to start supervisors.
Summary
Functions
Parses and validates a supervisor configuration.
Types
@type child_spec() :: %{ type: :group | :chain | :standalone, options: keyword(), workers: [worker_spec()] }
@type config() :: keyword()
@type parsed_config() :: %{options: keyword(), children: [child_spec()]}
Functions
@spec parse(config()) :: {:ok, parsed_config()} | {:error, any()}
Parses and validates a supervisor configuration.
Parameters
config- A keyword list containing supervisor configuration
Returns
{:ok, parsed_config}- Successfully parsed configuration{:error, reason}- Validation or parsing error
Expected Configuration Format
[
options: [
num_partitions: 2,
link: false,
strategy: :one_for_one
],
groups: [
[
id: :my_group,
restart_strategy: :one_for_one,
workers: [
[mfa: {MyModule, :my_function, [:arg1]}, options: [id: :worker1]],
[fun: fn -> :ok end, options: [id: :worker2]]
]
]
],
chains: [
[
id: :my_chain,
restart_strategy: :one_for_one,
send_type: :round_robin,
workers: [
[mfa: {MyModule, :step1, []}, options: [id: :step1]],
[mfa: {MyModule, :step2, []}, options: [id: :step2]]
]
]
],
workers: [
[mfa: {MyModule, :standalone_worker, []}, options: [id: :standalone1]]
]
]