PhoenixGenApi.Structs.PushConfig (PhoenixGenApi v2.11.0)

Copy Markdown View Source

Represents the data a remote node pushes to the PhoenixGenApi server node.

This struct is used when a remote node actively pushes its service configuration to the server, as opposed to the server pulling it. It contains all the necessary information to register the service, including function configurations and optional pull-based registration details.

Version Checking

The config_version field represents the version of the entire service configuration. When the server receives a push, it compares this version with the locally stored version. If they match, the push can be skipped since the server already has the current configuration.

Auto-Pull Registration

When module and function are provided, the to_service_config/1 function can convert this PushConfig into a ServiceConfig for automatic pull-based registration. This allows the server to periodically refresh the configuration from the remote node after the initial push.

Validation

Use valid?/1 for a quick boolean check or validate_with_details/1 for detailed error messages when validation fails.

Example

%PushConfig{
  service: "user_service",
  nodes: [:"node1@host", :"node2@host"],
  config_version: "1.2.3",
  fun_configs: [%FunConfig{...}],
  module: UserService.Api,
  function: :get_config,
  args: [],
  version_module: UserService.Api,
  version_function: :get_config_version,
  version_args: []
}

Summary

Types

t()

Push configuration struct for remote node pushes.

Functions

Creates a PushConfig struct from a map using Nestru for decoding.

Converts the PushConfig to a ServiceConfig for auto-pull registration.

Validates the push configuration.

Validates the push configuration and returns detailed error information.

Types

t()

@type t() :: %PhoenixGenApi.Structs.PushConfig{
  args: list(),
  config_version: String.t(),
  fun_configs: [PhoenixGenApi.Structs.FunConfig.t()],
  function: atom() | nil,
  module: module() | nil,
  nodes: [atom() | String.t()],
  service: atom() | String.t(),
  version_args: list(),
  version_function: atom() | nil,
  version_module: module() | nil
}

Push configuration struct for remote node pushes.

Functions

from_map(data)

Creates a PushConfig struct from a map using Nestru for decoding.

to_service_config(arg1)

@spec to_service_config(t()) :: PhoenixGenApi.Structs.ServiceConfig.t() | nil

Converts the PushConfig to a ServiceConfig for auto-pull registration.

Only creates a ServiceConfig if both module and function are provided. Returns nil if either is missing.

The resulting ServiceConfig can be used by the ConfigPuller to periodically refresh the configuration from the remote node.

valid?(config)

@spec valid?(t()) :: boolean()

Validates the push configuration.

Returns true if all configuration fields are valid, false otherwise. Logs detailed error messages for each invalid field.

Validation Checks

  • service must not be nil
  • nodes must be a non-empty list of atoms or strings
  • config_version must be a non-empty string
  • fun_configs must be a non-empty list of FunConfig structs
  • All fun_configs must have the same service name as the push config
  • All fun_configs must have valid versions

validate_with_details(config)

@spec validate_with_details(t()) :: {:ok, t()} | {:error, [String.t()]}

Validates the push configuration and returns detailed error information.

Returns {:ok, config} if valid, or {:error, [error_messages]} if invalid.