And Balances were backfilled unto the database.

pull/42/head
CJ Bryan and Desmond Bowe 7 years ago
parent 937b5bd24a
commit 1751d1aed4
  1. 1
      Procfile
  2. 21
      lib/explorer/skipped_balances.ex
  3. 26
      lib/mix/tasks/scrape.balances.ex
  4. 18
      test/explorer/skipped_balances_test.exs

@ -4,3 +4,4 @@ scheduler: bin/start-pgbouncer-stunnel mix exq.start scheduler
blocks: bin/start-pgbouncer-stunnel mix scrape.blocks 1000000
receipts: bin/start-pgbouncer-stunnel mix scrape.receipts 10000
internal_transactions: bin/start-pgbouncer-stunnel mix scrape.internal_transactions 10000
balances: bin/start-pgbouncer-stunnel mix scrape.balances 1000000

@ -0,0 +1,21 @@
defmodule Explorer.SkippedBalances do
@moduledoc "Gets a list of Addresses that do not have balances."
alias Explorer.Address
alias Explorer.Repo
import Ecto.Query, only: [from: 2]
def fetch(count) do
query =
from(
address in Address,
select: address.hash,
where: is_nil(address.balance),
limit: ^count
)
query
|> Repo.all()
end
end

@ -0,0 +1,26 @@
defmodule Mix.Tasks.Scrape.Balances do
@moduledoc "Populate Address balances."
use Mix.Task
alias Explorer.Repo
alias Explorer.SkippedBalances
alias Explorer.BalanceImporter
def run([]), do: run(1)
def run(count) do
[:postgrex, :ecto, :ethereumex, :tzdata]
|> Enum.each(&Application.ensure_all_started/1)
Repo.start_link()
Exq.start_link(mode: :enqueuer)
"#{count}"
|> String.to_integer()
|> SkippedBalances.fetch()
|> Flow.from_enumerable()
|> Flow.map(&BalanceImporter.import/1)
|> Enum.to_list()
end
end

@ -0,0 +1,18 @@
defmodule Explorer.SkippedBalancesTest do
use Explorer.DataCase
alias Explorer.SkippedBalances
describe "fetch/1" do
test "returns a list of address hashes that do not have balances" do
insert(:address, hash: "0xcashews", balance: nil)
assert SkippedBalances.fetch(1) == ["0xcashews"]
end
test "only get a limited set of addresses" do
insert_list(10, :address, balance: nil)
insert_list(5, :address, balance: 55)
assert length(SkippedBalances.fetch(7)) == 7
end
end
end
Loading…
Cancel
Save