SuperWorker.ConfigLoader.Parser (SuperWorker v0.3.6)

View Source

Parses 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

Types

child_spec()

@type child_spec() :: %{
  type: :group | :chain | :standalone,
  options: keyword(),
  workers: [worker_spec()]
}

config()

@type config() :: keyword()

parsed_config()

@type parsed_config() :: %{options: keyword(), children: [child_spec()]}

worker_spec()

@type worker_spec() :: %{
  mfa: {module(), atom(), list()} | {:fun, function()},
  options: keyword()
}

Functions

add_default_options(specs)

convert_regular_child_spec(module)

parse(config)

@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]]
  ]
]