From d7a4706d036cd70549f2065fc669776f5aa6eb18 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Mon, 7 May 2018 20:04:35 -0500 Subject: [PATCH] mix format --- .../lib/explorer/indexer/address_fetcher.ex | 14 +++++++++----- .../explorer/lib/explorer/indexer/block_fetcher.ex | 10 +++------- apps/explorer/lib/explorer/indexer/supervisor.ex | 4 ++-- apps/explorer/lib/explorer/jsonrpc.ex | 2 +- apps/explorer/mix.exs | 2 ++ mix.exs | 1 + 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/apps/explorer/lib/explorer/indexer/address_fetcher.ex b/apps/explorer/lib/explorer/indexer/address_fetcher.ex index 39311ef1fd..b972f6c365 100644 --- a/apps/explorer/lib/explorer/indexer/address_fetcher.ex +++ b/apps/explorer/lib/explorer/indexer/address_fetcher.ex @@ -46,6 +46,7 @@ defmodule Explorer.Indexer.AddressFetcher do def handle_info(:flush, state) do {:noreply, state |> fetch_next_batch([]) |> schedule_next_buffer_flush()} end + def handle_info({:async_fetch, hashes}, state) do {:noreply, fetch_next_batch(state, hashes)} end @@ -105,6 +106,7 @@ defmodule Explorer.Indexer.AddressFetcher do if :queue.len(batch) > 0 do schedule_async_fetch(:queue.to_list(batch)) end + :ok end @@ -138,11 +140,13 @@ defmodule Explorer.Indexer.AddressFetcher do if Enum.count(state.tasks) < @max_concurrency and :queue.len(state.buffer) > 0 do {batch, new_queue} = take_batch(state.buffer) - task = Task.Supervisor.async_nolink(Explorer.Indexer.TaskSupervisor, fn -> - debug(state, fn -> "fetching #{Enum.count(batch)} balances" end) - {:ok, balances} = do_fetch_addresses(batch) - {:fetched_balances, balances} - end) + + task = + Task.Supervisor.async_nolink(Explorer.Indexer.TaskSupervisor, fn -> + debug(state, fn -> "fetching #{Enum.count(batch)} balances" end) + {:ok, balances} = do_fetch_addresses(batch) + {:fetched_balances, balances} + end) %{state | tasks: Map.put(state.tasks, task.ref, batch), buffer: new_queue} else diff --git a/apps/explorer/lib/explorer/indexer/block_fetcher.ex b/apps/explorer/lib/explorer/indexer/block_fetcher.ex index 50cf8d98b1..403ff6bba7 100644 --- a/apps/explorer/lib/explorer/indexer/block_fetcher.ex +++ b/apps/explorer/lib/explorer/indexer/block_fetcher.ex @@ -11,7 +11,7 @@ defmodule Explorer.Indexer.BlockFetcher do alias Explorer.Indexer.{ Sequence, - BlockImporter, + BlockImporter } alias Explorer.JSONRPC.Transactions @@ -27,7 +27,6 @@ defmodule Explorer.Indexer.BlockFetcher do @receipts_batch_size 250 @receipts_concurrency 20 - @doc """ Starts the server. @@ -54,7 +53,7 @@ defmodule Explorer.Indexer.BlockFetcher do state = %{ genesis_task: nil, debug_logs: Keyword.get(opts, :debug_logs, false), - realtime_interval: (opts[:block_rate] || @block_rate) * 2, + realtime_interval: (opts[:block_rate] || @block_rate) * 2 } {:ok, state} @@ -152,8 +151,7 @@ defmodule Explorer.Indexer.BlockFetcher do |> Enum.chunk_every(@receipts_batch_size) |> Task.async_stream(&JSONRPC.fetch_transaction_receipts(&1), stream_opts) |> Enum.reduce_while({:ok, %{logs: [], receipts: []}}, fn - {:ok, {:ok, %{logs: logs, receipts: receipts}}}, - {:ok, %{logs: acc_logs, receipts: acc_receipts}} -> + {:ok, {:ok, %{logs: logs, receipts: receipts}}}, {:ok, %{logs: acc_logs, receipts: acc_receipts}} -> {:cont, {:ok, %{logs: acc_logs ++ logs, receipts: acc_receipts ++ receipts}}} {:ok, {:error, reason}}, {:ok, _acc} -> @@ -214,7 +212,6 @@ defmodule Explorer.Indexer.BlockFetcher do {:ok, receipt_params} <- fetch_transaction_receipts(state, transaction_hashes), %{logs: logs, receipts: receipts} <- receipt_params, {:ok, internal_transactions} <- fetch_internal_transactions(state, transaction_hashes) do - insert(state, seq, range, %{ blocks: blocks, internal_transactions: internal_transactions, @@ -222,7 +219,6 @@ defmodule Explorer.Indexer.BlockFetcher do receipts: receipts, transactions: transactions }) - else {:error, reason} -> debug(state, fn -> diff --git a/apps/explorer/lib/explorer/indexer/supervisor.ex b/apps/explorer/lib/explorer/indexer/supervisor.ex index 1f25943d24..bedbdaac96 100644 --- a/apps/explorer/lib/explorer/indexer/supervisor.ex +++ b/apps/explorer/lib/explorer/indexer/supervisor.ex @@ -8,7 +8,7 @@ defmodule Explorer.Indexer.Supervisor do alias Explorer.Indexer.{ BlockFetcher, BlockImporter, - AddressFetcher, + AddressFetcher } def start_link(opts) do @@ -21,7 +21,7 @@ defmodule Explorer.Indexer.Supervisor do {Task.Supervisor, name: Explorer.Indexer.TaskSupervisor}, {BlockFetcher, []}, {BlockImporter, []}, - {AddressFetcher, []}, + {AddressFetcher, []} ] Supervisor.init(children, strategy: :rest_for_one) diff --git a/apps/explorer/lib/explorer/jsonrpc.ex b/apps/explorer/lib/explorer/jsonrpc.ex index 776e5049c5..53408d015f 100644 --- a/apps/explorer/lib/explorer/jsonrpc.ex +++ b/apps/explorer/lib/explorer/jsonrpc.ex @@ -151,7 +151,7 @@ defmodule Explorer.JSONRPC do |> json_rpc(config(:url)) |> handle_get_block_by_number() |> case do - {:ok, _next, results} -> {:ok, results} + {:ok, _next, results} -> {:ok, results} {:error, reason} -> {:error, reason} end end diff --git a/apps/explorer/mix.exs b/apps/explorer/mix.exs index eb37aed4b4..7dacf37811 100644 --- a/apps/explorer/mix.exs +++ b/apps/explorer/mix.exs @@ -105,7 +105,9 @@ defmodule Explorer.Mixfile do test: ["ecto.drop", "ecto.create --quiet", "ecto.migrate", "test"] ] ++ env_aliases(env) end + defp env_aliases(:dev), do: [] + defp env_aliases(_env) do [compile: "compile --warnings-as-errors"] end diff --git a/mix.exs b/mix.exs index 6b7e26a243..79bbdb3311 100644 --- a/mix.exs +++ b/mix.exs @@ -30,6 +30,7 @@ defmodule ExplorerUmbrella.Mixfile do defp aliases(:dev) do [] end + defp aliases(_env) do [ compile: "compile --warnings-as-errors"