Merge pull request #3043 from poanetwork/vb-add-host-name

Extract host name for split couple of indexer and web app
pull/3044/head
Victor Baranov 5 years ago committed by GitHub
commit 89d0a35468
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 13
      apps/explorer/lib/explorer/chain.ex
  3. 3
      apps/explorer/lib/explorer/chain/events/listener.ex
  4. 17
      apps/explorer/test/explorer/chain_test.exs

@ -3,6 +3,7 @@
### Features
### Fixes
- [#3043](https://github.com/poanetwork/blockscout/pull/3043) - Extract host name for split couple of indexer and web app
- [#3042](https://github.com/poanetwork/blockscout/pull/3042) - Speedup pending txs list query
- [#2944](https://github.com/poanetwork/blockscout/pull/2944) - Split js logic into multiple files

@ -4073,6 +4073,19 @@ defmodule Explorer.Chain do
end
end
def extract_db_host(db_url) do
if db_url == nil do
""
else
db_url
|> String.split("@")
|> Enum.take(-1)
|> Enum.at(0)
|> String.split(":")
|> Enum.at(0)
end
end
@doc """
Fetches the first trace from the Parity trace URL.
"""

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

@ -4887,6 +4887,23 @@ defmodule Explorer.ChainTest do
end
end
describe "extract_db_host/1" do
test "extracts correct db host" do
db_url = "postgresql://viktor:@localhost:5432/blockscout-dev-1"
assert Chain.extract_db_host(db_url) == "localhost"
end
test "returns empty db name" do
db_url = ""
assert Chain.extract_db_host(db_url) == ""
end
test "returns nil db name" do
db_url = nil
assert Chain.extract_db_host(db_url) == ""
end
end
describe "fetch_first_trace/2" do
test "fetched first trace", %{
json_rpc_named_arguments: json_rpc_named_arguments

Loading…
Cancel
Save