A server-side GenServer that receives pushed configs from remote nodes.
Remote nodes can push their service configurations to the server/gateway node
using this module. The receiver validates the pushed data, stores it in
ConfigDb, and optionally registers the service with ConfigPuller for
auto-pull.
Push Mechanism
When a remote node pushes a PushConfig, the receiver:
- Validates the
PushConfigstruct - Compares the
config_versionwith the locally stored version - If the version matches (and
:forceis not set), the push is skipped - If new or forced:
- Validates all
FunConfigitems - Enforces the service name on each
FunConfig - Ensures each
FunConfighas a version (defaults to"0.0.0") - Stores them in
ConfigDbviaConfigDb.batch_add/1 - Stores the
PushConfigin state - If the
PushConfighasmodule/functionfor auto-pull, registers it withConfigPullerviaConfigPuller.add/1
- Validates all
Atomicity
The push operation is atomic — either all configs are stored or none. If
validation fails for the PushConfig or any FunConfig item, the entire
push is rejected.
Important Notes
- This module runs on the server/gateway node (not
client_mode) - It should NOT be started when
client_mode: true
Summary
Functions
Returns a specification to start this module under a supervisor.
Removes a pushed service from the receiver's state.
Returns a map of all pushed services and their config versions.
Returns the PushConfig for a given service name, or nil.
Receives a PushConfig struct (or map that can be decoded into one).
Same as push/1 but with options.
Starts the ConfigReceiver GenServer.
Verifies that the server has the given service and config_version.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Removes a pushed service from the receiver's state.
Also removes the service from ConfigPuller if it was registered for
auto-pull.
Returns a map of all pushed services and their config versions.
@spec get_pushed_config(String.t() | atom()) :: PhoenixGenApi.Structs.PushConfig.t() | nil
Returns the PushConfig for a given service name, or nil.
@spec push(PhoenixGenApi.Structs.PushConfig.t() | map()) :: {:ok, :accepted} | {:ok, :skipped, term()} | {:error, term()}
Receives a PushConfig struct (or map that can be decoded into one).
Validates the PushConfig, checks the version, and stores the configs
if the version is new. If the config_version matches what is already
stored, the push is skipped.
Returns
{:ok, :accepted}- New configs were stored successfully{:ok, :skipped, reason}- Push was skipped (e.g., version matches){:error, reason}- Validation failure
@spec push( PhoenixGenApi.Structs.PushConfig.t() | map(), keyword() ) :: {:ok, :accepted} | {:ok, :skipped, term()} | {:error, term()}
Same as push/1 but with options.
Options
:force- Force push even if version matches (default:false)
Starts the ConfigReceiver GenServer.
@spec verify(String.t() | atom(), String.t()) :: {:ok, :matched} | {:ok, :mismatch, String.t()} | {:error, :not_found}
Verifies that the server has the given service and config_version.
Parameters
service- The service name (string or atom)config_version- The config version string to verify
Returns
{:ok, :matched}- Version matches what is stored{:ok, :mismatch, stored_version}- Version differs from what is stored{:error, :not_found}- Service is not known