PushX.Config (PushX v0.11.0)

Copy Markdown View Source

Configuration management for PushX.

Configuration Options

APNS (Apple Push Notification Service)

  • :apns_key_id - The Key ID from Apple Developer Portal
  • :apns_team_id - Your Apple Developer Team ID
  • :apns_private_key - The private key, either:
    • A raw PEM string
    • {:file, "/path/to/AuthKey.p8"}
    • {:system, "ENV_VAR_NAME"}
  • :apns_mode - :prod or :sandbox (default: :prod)

FCM (Firebase Cloud Messaging)

  • :fcm_project_id - Your Firebase project ID
  • :fcm_credentials - Service account credentials, either:
    • {:file, "/path/to/service-account.json"}
    • {:json, "...json string..."}
    • {:system, "ENV_VAR_NAME"} (expects JSON string)

Finch Pool

  • :finch_name - Name of the Finch pool (default: PushX.Finch)
  • :finch_pool_size - Connections per pool (default: 25)
  • :finch_pool_count - Number of pools (default: 2)

Request Timeouts

  • :receive_timeout - Timeout for receiving response in ms (default: 15_000)
  • :pool_timeout - Timeout for acquiring connection from pool in ms (default: 5_000)
  • :connect_timeout - TCP connection timeout in ms (default: 10_000)

Retry Settings

  • :retry_enabled - Enable automatic retry (default: true)
  • :retry_max_attempts - Maximum retry attempts (default: 3)
  • :retry_base_delay_ms - Base delay in milliseconds (default: 10_000)
  • :retry_max_delay_ms - Maximum delay in milliseconds (default: 60_000)

Example Configuration

config :pushx,
  apns_key_id: "ABC123DEFG",
  apns_team_id: "TEAM123456",
  apns_private_key: {:file, "priv/keys/AuthKey.p8"},
  apns_mode: :prod,
  fcm_project_id: "my-project-id",
  fcm_credentials: {:file, "priv/keys/firebase.json"}

Summary

Functions

Checks if APNS is configured.

Gets the APNS Key ID.

Gets the APNS mode (:prod or :sandbox).

Gets the APNS private key content. Supports file paths, environment variables, and raw strings.

Gets the APNS Team ID.

Gets the cooldown time in milliseconds before the circuit transitions from :open to :half_open. Default: 30 seconds.

Checks if the circuit breaker is enabled. Default: false (opt-in feature).

Gets the number of consecutive failures before the circuit opens. Default: 5.

Gets the TCP connection timeout in milliseconds. Default: 10 seconds.

Checks if FCM is configured.

Gets the FCM credentials for Goth. Returns a map suitable for Goth configuration.

Gets the FCM project ID.

Gets the Finch pool name.

Gets the Finch pool count (number of connection pools).

Gets the Finch pool size (connections per pool).

Returns the Finch request options with configured timeouts.

Gets a configuration value.

Gets a required configuration value. Raises if the value is not configured.

Gets the callback for invalid token cleanup.

Gets the pool timeout (time to wait for a connection from pool) in milliseconds. Default: 5 seconds.

Gets the receive timeout (time to wait for response data) in milliseconds. Default: 15 seconds.

request_timeout() deprecated

Gets the overall request timeout in milliseconds. Default: 30 seconds.

Gets the base delay for exponential backoff in milliseconds. Default: 10 seconds (Google's recommended minimum).

Checks if retry is enabled.

Gets the maximum number of retry attempts.

Gets the maximum delay for exponential backoff in milliseconds. Default: 60 seconds.

Functions

apns_configured?()

@spec apns_configured?() :: boolean()

Checks if APNS is configured.

apns_key_id()

@spec apns_key_id() :: String.t()

Gets the APNS Key ID.

apns_mode()

@spec apns_mode() :: :prod | :sandbox

Gets the APNS mode (:prod or :sandbox).

apns_private_key()

@spec apns_private_key() :: String.t()

Gets the APNS private key content. Supports file paths, environment variables, and raw strings.

apns_team_id()

@spec apns_team_id() :: String.t()

Gets the APNS Team ID.

circuit_breaker_cooldown_ms()

@spec circuit_breaker_cooldown_ms() :: pos_integer()

Gets the cooldown time in milliseconds before the circuit transitions from :open to :half_open. Default: 30 seconds.

circuit_breaker_enabled?()

@spec circuit_breaker_enabled?() :: boolean()

Checks if the circuit breaker is enabled. Default: false (opt-in feature).

circuit_breaker_threshold()

@spec circuit_breaker_threshold() :: pos_integer()

Gets the number of consecutive failures before the circuit opens. Default: 5.

connect_timeout()

@spec connect_timeout() :: pos_integer()

Gets the TCP connection timeout in milliseconds. Default: 10 seconds.

fcm_configured?()

@spec fcm_configured?() :: boolean()

Checks if FCM is configured.

fcm_credentials()

@spec fcm_credentials() :: map() | {:file, String.t()}

Gets the FCM credentials for Goth. Returns a map suitable for Goth configuration.

fcm_project_id()

@spec fcm_project_id() :: String.t()

Gets the FCM project ID.

finch_name()

@spec finch_name() :: atom()

Gets the Finch pool name.

finch_pool_count()

@spec finch_pool_count() :: pos_integer()

Gets the Finch pool count (number of connection pools).

Default: 2 (increased from 1 in v0.6.0 to handle traffic bursts better)

finch_pool_size()

@spec finch_pool_size() :: pos_integer()

Gets the Finch pool size (connections per pool).

Default: 25 (increased from 10 in v0.6.0 to handle traffic bursts better)

finch_request_opts()

@spec finch_request_opts() :: keyword()

Returns the Finch request options with configured timeouts.

get(key, default \\ nil)

@spec get(atom(), any()) :: any()

Gets a configuration value.

get!(key)

@spec get!(atom()) :: any()

Gets a required configuration value. Raises if the value is not configured.

on_invalid_token()

@spec on_invalid_token() :: {module(), atom(), list()} | nil

Gets the callback for invalid token cleanup.

When set, this MFA tuple is called asynchronously whenever a push returns :invalid_token, :expired_token, or :unregistered.

The callback receives (provider, token, ...extra_args).

Example

config :pushx,
  on_invalid_token: {MyApp.Push, :handle_invalid_token, []}

pool_timeout()

@spec pool_timeout() :: pos_integer()

Gets the pool timeout (time to wait for a connection from pool) in milliseconds. Default: 5 seconds.

receive_timeout()

@spec receive_timeout() :: pos_integer()

Gets the receive timeout (time to wait for response data) in milliseconds. Default: 15 seconds.

request_timeout()

This function is deprecated. Not used by Finch. Use receive_timeout/0 and pool_timeout/0 instead..
@spec request_timeout() :: pos_integer()

Gets the overall request timeout in milliseconds. Default: 30 seconds.

Note: This value is not currently passed to Finch requests. Use :receive_timeout and :pool_timeout instead.

retry_base_delay_ms()

@spec retry_base_delay_ms() :: pos_integer()

Gets the base delay for exponential backoff in milliseconds. Default: 10 seconds (Google's recommended minimum).

retry_enabled?()

@spec retry_enabled?() :: boolean()

Checks if retry is enabled.

retry_max_attempts()

@spec retry_max_attempts() :: pos_integer()

Gets the maximum number of retry attempts.

retry_max_delay_ms()

@spec retry_max_delay_ms() :: pos_integer()

Gets the maximum delay for exponential backoff in milliseconds. Default: 60 seconds.