Packages

Library for making RPC calls to nodes in other fly.io regions. Specifically designed to make it easier to execute code in the "primary" region.

Current section

Files

Jump to
fly_rpc lib fly.ex
Raw

lib/fly.ex

defmodule Fly do
@moduledoc """
Functions and features to help Elixir applications more easily take advantage
of the features that Fly.io provides.
"""
@doc """
Return the configured primary region. Reads and requires an ENV setting for
`PRIMARY_REGION`.
"""
def primary_region do
System.fetch_env!("PRIMARY_REGION")
end
@doc """
Return the configured current region. Reads the `FLY_REGION` ENV setting
that's available when deployed on the Fly.io platform.
"""
def my_region do
System.fetch_env!("FLY_REGION")
end
@doc """
Return if the app instance is running in the primary region or not. Boolean
result.
"""
@spec is_primary? :: no_return() | boolean()
def is_primary? do
my_region() == primary_region()
end
@doc false
# A "private" function that converts the MFA data into a string for logging.
def mfa_string(module, func, args) do
"#{Atom.to_string(module)}.#{Atom.to_string(func)}/#{length(args)}"
end
end