Fix splitting setup

pull/3025/head
Victor Baranov 5 years ago
parent 9db6d5a160
commit a62516913a
  1. 1
      CHANGELOG.md
  2. 11
      apps/explorer/lib/explorer/chain.ex
  3. 9
      apps/explorer/lib/explorer/chain/events/listener.ex
  4. 17
      apps/explorer/test/explorer/chain_test.exs

@ -5,6 +5,7 @@
- [#2834](https://github.com/poanetwork/blockscout/pull/2834) - always redirect to checksummed hash
### Fixes
- [#3025](https://github.com/poanetwork/blockscout/pull/3025) - Fix splitting of indexer/web components setup
- [#3021](https://github.com/poanetwork/blockscout/pull/3021), [#3022](https://github.com/poanetwork/blockscout/pull/3022) - Refine dev/test config
- [#3016](https://github.com/poanetwork/blockscout/pull/3016), [#3017](https://github.com/poanetwork/blockscout/pull/3017) - Fix token instance QR code data
- [#3014](https://github.com/poanetwork/blockscout/pull/3014) - Fix checksum address feature for tokens pages

@ -4033,4 +4033,15 @@ defmodule Explorer.Chain do
defp boolean_to_check_result(true), do: :ok
defp boolean_to_check_result(false), do: :not_found
def extract_db_name(db_url) do
if db_url == nil do
""
else
db_url
|> String.split("/")
|> Enum.take(-1)
|> Enum.at(0)
end
end
end

@ -6,15 +6,22 @@ defmodule Explorer.Chain.Events.Listener do
use GenServer
alias Postgrex.Notifications
import Explorer.Chain, only: [extract_db_name: 1]
def start_link(_) do
GenServer.start_link(__MODULE__, "chain_event", name: __MODULE__)
end
def init(channel) do
{:ok, pid} =
explorer_repo =
:explorer
|> Application.get_env(Explorer.Repo)
db_url = explorer_repo[:url]
{:ok, pid} =
explorer_repo
|> Keyword.put(:database, extract_db_name(db_url))
|> Notifications.start_link()
ref = Notifications.listen!(pid, channel)

@ -4608,4 +4608,21 @@ defmodule Explorer.ChainTest do
assert third.delta == Decimal.new(1)
end
end
describe "extract_db_name/1" do
test "extracts correct db name" do
db_url = "postgresql://viktor:@localhost:5432/blockscout-dev-1"
assert Chain.extract_db_name(db_url) == "blockscout-dev-1"
end
test "returns empty db name" do
db_url = ""
assert Chain.extract_db_name(db_url) == ""
end
test "returns nil db name" do
db_url = nil
assert Chain.extract_db_name(db_url) == ""
end
end
end

Loading…
Cancel
Save