Skip to content

Commit

Permalink
fix: add default region nodes when no direct region mapping (#767)
Browse files Browse the repository at this point in the history
* fix: add default region nodes when no direct region mapping

* feat: support aws ap-east-1 tenant region mapping
  • Loading branch information
w3b6x9 authored Dec 23, 2023
1 parent 998e5c0 commit 1a1ccba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/realtime/nodes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ defmodule Realtime.Nodes do
"ap-northeast-1" -> "ap-southeast-1"
"ap-northeast-2" -> "ap-southeast-1"
"ap-southeast-2" -> "ap-southeast-2"
"ap-east-1" -> "ap-southeast-1"
"ap-south-1" -> "ap-southeast-1"
"eu-west-1" -> "eu-west-2"
"eu-west-2" -> "eu-west-2"
Expand All @@ -65,6 +66,7 @@ defmodule Realtime.Nodes do
"ap-northeast-1" -> "syd"
"ap-northeast-2" -> "syd"
"ap-southeast-2" -> "syd"
"ap-east-1" -> "syd"
"ap-south-1" -> "syd"
"eu-west-1" -> "lhr"
"eu-west-2" -> "lhr"
Expand All @@ -81,20 +83,22 @@ defmodule Realtime.Nodes do
is unstable.
"""

@spec region_nodes(String.t()) :: [atom()]
@spec region_nodes(String.t() | nil) :: [atom()]
def region_nodes(region) when is_binary(region) do
:syn.members(RegionNodes, region)
|> Enum.map(fn {_pid, [node: node]} -> node end)
|> Enum.sort()
end

def region_nodes(nil), do: []

@doc """
Picks the node to launch the Postgres connection on.
If there are not two nodes in a region the connection is established from
the `default` node given.
"""
@spec launch_node(String.t(), String.t(), atom()) :: atom()
@spec launch_node(String.t(), String.t() | nil, atom()) :: atom()
def launch_node(tenant_id, region, default) do
case region_nodes(region) do
[node] ->
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Realtime.MixProject do
def project do
[
app: :realtime,
version: "2.25.47",
version: "2.25.48",
elixir: "~> 1.14.0",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down

0 comments on commit 1a1ccba

Please sign in to comment.