Land #331: Extract Explorer.Indexer to Indexer
commit
2066427b29
@ -1,26 +0,0 @@ |
|||||||
defmodule Explorer.Indexer.Supervisor do |
|
||||||
@moduledoc """ |
|
||||||
Supervising the fetchers for the `Explorer.Indexer` |
|
||||||
""" |
|
||||||
|
|
||||||
use Supervisor |
|
||||||
|
|
||||||
alias Explorer.Indexer.{AddressBalanceFetcher, BlockFetcher, InternalTransactionFetcher, PendingTransactionFetcher} |
|
||||||
|
|
||||||
def start_link(opts) do |
|
||||||
Supervisor.start_link(__MODULE__, opts, name: __MODULE__) |
|
||||||
end |
|
||||||
|
|
||||||
@impl Supervisor |
|
||||||
def init(_opts) do |
|
||||||
children = [ |
|
||||||
{Task.Supervisor, name: Explorer.Indexer.TaskSupervisor}, |
|
||||||
{AddressBalanceFetcher, name: AddressBalanceFetcher}, |
|
||||||
{PendingTransactionFetcher, name: PendingTransactionFetcher}, |
|
||||||
{InternalTransactionFetcher, name: InternalTransactionFetcher}, |
|
||||||
{BlockFetcher, []} |
|
||||||
] |
|
||||||
|
|
||||||
Supervisor.init(children, strategy: :one_for_one) |
|
||||||
end |
|
||||||
end |
|
@ -0,0 +1,4 @@ |
|||||||
|
# Used by "mix format" |
||||||
|
[ |
||||||
|
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"] |
||||||
|
] |
@ -0,0 +1,24 @@ |
|||||||
|
# The directory Mix will write compiled artifacts to. |
||||||
|
/_build/ |
||||||
|
|
||||||
|
# If you run "mix test --cover", coverage assets end up here. |
||||||
|
/cover/ |
||||||
|
|
||||||
|
# The directory Mix downloads your dependencies sources to. |
||||||
|
/deps/ |
||||||
|
|
||||||
|
# Where 3rd-party dependencies like ExDoc output generated docs. |
||||||
|
/doc/ |
||||||
|
|
||||||
|
# Ignore .fetch files in case you like to edit your project deps locally. |
||||||
|
/.fetch |
||||||
|
|
||||||
|
# If the VM crashes, it generates a dump, let's ignore it too. |
||||||
|
erl_crash.dump |
||||||
|
|
||||||
|
# Also ignore archive artifacts (built via "mix archive.build"). |
||||||
|
*.ez |
||||||
|
|
||||||
|
# Ignore package tarball (built via "mix hex.build"). |
||||||
|
indexer-*.tar |
||||||
|
|
@ -0,0 +1,21 @@ |
|||||||
|
# Indexer |
||||||
|
|
||||||
|
**TODO: Add description** |
||||||
|
|
||||||
|
## Installation |
||||||
|
|
||||||
|
If [available in Hex](https://hex.pm/docs/publish), the package can be installed |
||||||
|
by adding `indexer` to your list of dependencies in `mix.exs`: |
||||||
|
|
||||||
|
```elixir |
||||||
|
def deps do |
||||||
|
[ |
||||||
|
{:indexer, "~> 0.1.0"} |
||||||
|
] |
||||||
|
end |
||||||
|
``` |
||||||
|
|
||||||
|
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) |
||||||
|
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can |
||||||
|
be found at [https://hexdocs.pm/indexer](https://hexdocs.pm/indexer). |
||||||
|
|
@ -0,0 +1,9 @@ |
|||||||
|
# This file is responsible for configuring your application |
||||||
|
# and its dependencies with the aid of the Mix.Config module. |
||||||
|
use Mix.Config |
||||||
|
|
||||||
|
config :indexer, |
||||||
|
block_rate: 5_000, |
||||||
|
debug_logs: !!System.get_env("DEBUG_INDEXER") |
||||||
|
|
||||||
|
config :indexer, ecto_repos: [Explorer.Repo] |
@ -0,0 +1,24 @@ |
|||||||
|
defmodule Indexer.Application do |
||||||
|
@moduledoc """ |
||||||
|
This is the `Application` module for `Indexer`. |
||||||
|
""" |
||||||
|
|
||||||
|
use Application |
||||||
|
|
||||||
|
alias Indexer.{AddressBalanceFetcher, BlockFetcher, InternalTransactionFetcher, PendingTransactionFetcher} |
||||||
|
|
||||||
|
@impl Application |
||||||
|
def start(_type, _args) do |
||||||
|
children = [ |
||||||
|
{Task.Supervisor, name: Indexer.TaskSupervisor}, |
||||||
|
{AddressBalanceFetcher, name: AddressBalanceFetcher}, |
||||||
|
{PendingTransactionFetcher, name: PendingTransactionFetcher}, |
||||||
|
{InternalTransactionFetcher, name: InternalTransactionFetcher}, |
||||||
|
{BlockFetcher, []} |
||||||
|
] |
||||||
|
|
||||||
|
opts = [strategy: :one_for_one, name: Indexer.Supervisor] |
||||||
|
|
||||||
|
Supervisor.start_link(children, opts) |
||||||
|
end |
||||||
|
end |
@ -1,4 +1,4 @@ |
|||||||
defmodule Explorer.Indexer.Sequence do |
defmodule Indexer.Sequence do |
||||||
@moduledoc false |
@moduledoc false |
||||||
|
|
||||||
use Agent |
use Agent |
@ -0,0 +1,49 @@ |
|||||||
|
defmodule Indexer.MixProject do |
||||||
|
use Mix.Project |
||||||
|
|
||||||
|
def project do |
||||||
|
[ |
||||||
|
aliases: aliases(), |
||||||
|
app: :indexer, |
||||||
|
version: "0.1.0", |
||||||
|
build_path: "../../_build", |
||||||
|
config_path: "../../config/config.exs", |
||||||
|
deps_path: "../../deps", |
||||||
|
lockfile: "../../mix.lock", |
||||||
|
elixir: "~> 1.6", |
||||||
|
elixirc_paths: elixirc_paths(Mix.env()), |
||||||
|
start_permanent: Mix.env() == :prod, |
||||||
|
deps: deps() |
||||||
|
] |
||||||
|
end |
||||||
|
|
||||||
|
# Run "mix help compile.app" to learn about applications. |
||||||
|
def application do |
||||||
|
[ |
||||||
|
extra_applications: [:logger], |
||||||
|
mod: {Indexer.Application, []} |
||||||
|
] |
||||||
|
end |
||||||
|
|
||||||
|
defp aliases do |
||||||
|
[ |
||||||
|
# so that the supervision tree does not start, which would begin indexing, and so that the various fetchers can |
||||||
|
# be started with `ExUnit`'s `start_supervised` for unit testing. |
||||||
|
test: "test --no-start" |
||||||
|
] |
||||||
|
end |
||||||
|
|
||||||
|
# Run "mix help deps" to learn about dependencies. |
||||||
|
defp deps do |
||||||
|
[ |
||||||
|
# JSONRPC access to Parity for `Explorer.Indexer` |
||||||
|
{:ethereum_jsonrpc, in_umbrella: true}, |
||||||
|
# Importing to database |
||||||
|
{:explorer, in_umbrella: true} |
||||||
|
] |
||||||
|
end |
||||||
|
|
||||||
|
# Specifies which paths to compile per environment. |
||||||
|
defp elixirc_paths(:test), do: ["test/support" | elixirc_paths(:dev)] |
||||||
|
defp elixirc_paths(_), do: ["lib"] |
||||||
|
end |
@ -1,7 +1,7 @@ |
|||||||
defmodule Explorer.BufferedTaskTest do |
defmodule Indexer.BufferedTaskTest do |
||||||
use ExUnit.Case, async: true |
use ExUnit.Case, async: true |
||||||
|
|
||||||
alias Explorer.BufferedTask |
alias Indexer.BufferedTask |
||||||
|
|
||||||
@max_batch_size 2 |
@max_batch_size 2 |
||||||
|
|
@ -1,16 +1,16 @@ |
|||||||
defmodule Explorer.Indexer.PendingTransactionFetcherTest do |
defmodule Indexer.PendingTransactionFetcherTest do |
||||||
# `async: false` due to use of named GenServer |
# `async: false` due to use of named GenServer |
||||||
use Explorer.DataCase, async: false |
use Explorer.DataCase, async: false |
||||||
|
|
||||||
alias Explorer.Chain.Transaction |
alias Explorer.Chain.Transaction |
||||||
alias Explorer.Indexer.PendingTransactionFetcher |
alias Indexer.PendingTransactionFetcher |
||||||
|
|
||||||
describe "start_link/1" do |
describe "start_link/1" do |
||||||
# this test may fail if Sokol so low volume that the pending transactions are empty for too long |
# this test may fail if Sokol so low volume that the pending transactions are empty for too long |
||||||
test "starts fetching pending transactions" do |
test "starts fetching pending transactions" do |
||||||
assert Repo.aggregate(Transaction, :count, :hash) == 0 |
assert Repo.aggregate(Transaction, :count, :hash) == 0 |
||||||
|
|
||||||
start_supervised!({Task.Supervisor, name: Explorer.Indexer.TaskSupervisor}) |
start_supervised!({Task.Supervisor, name: Indexer.TaskSupervisor}) |
||||||
start_supervised!(PendingTransactionFetcher) |
start_supervised!(PendingTransactionFetcher) |
||||||
|
|
||||||
wait_for_results(fn -> |
wait_for_results(fn -> |
@ -1,7 +1,7 @@ |
|||||||
defmodule Explorer.Indexer.SequenceTest do |
defmodule Indexer.SequenceTest do |
||||||
use ExUnit.Case |
use ExUnit.Case |
||||||
|
|
||||||
alias Explorer.Indexer.Sequence |
alias Indexer.Sequence |
||||||
|
|
||||||
test "start_link" do |
test "start_link" do |
||||||
{:ok, pid} = Sequence.start_link([1..4], 5, 1) |
{:ok, pid} = Sequence.start_link([1..4], 5, 1) |
@ -1,8 +1,6 @@ |
|||||||
defmodule Explorer.IndexerTest do |
defmodule IndexerTest do |
||||||
use Explorer.DataCase, async: true |
use Explorer.DataCase, async: true |
||||||
|
|
||||||
alias Explorer.Indexer |
|
||||||
|
|
||||||
import Explorer.Factory |
import Explorer.Factory |
||||||
|
|
||||||
doctest Indexer |
doctest Indexer |
@ -1,5 +1,5 @@ |
|||||||
defmodule Explorer.Indexer.AddressBalanceFetcherCase do |
defmodule Indexer.AddressBalanceFetcherCase do |
||||||
alias Explorer.Indexer.AddressBalanceFetcher |
alias Indexer.AddressBalanceFetcher |
||||||
|
|
||||||
def start_supervised!(options \\ []) when is_list(options) do |
def start_supervised!(options \\ []) when is_list(options) do |
||||||
options |
options |
@ -1,5 +1,5 @@ |
|||||||
defmodule Explorer.Indexer.InternalTransactionFetcherCase do |
defmodule Indexer.InternalTransactionFetcherCase do |
||||||
alias Explorer.Indexer.InternalTransactionFetcher |
alias Indexer.InternalTransactionFetcher |
||||||
|
|
||||||
def start_supervised!(options \\ []) when is_list(options) do |
def start_supervised!(options \\ []) when is_list(options) do |
||||||
options |
options |
@ -0,0 +1,20 @@ |
|||||||
|
# https://github.com/CircleCI-Public/circleci-demo-elixir-phoenix/blob/a89de33a01df67b6773ac90adc74c34367a4a2d6/test/test_helper.exs#L1-L3 |
||||||
|
junit_folder = Mix.Project.build_path() <> "/junit/#{Mix.Project.config()[:app]}" |
||||||
|
File.mkdir_p!(junit_folder) |
||||||
|
:ok = Application.put_env(:junit_formatter, :report_dir, junit_folder) |
||||||
|
|
||||||
|
# start all dependencies, but not Indexer itself as we need to unit test the supervision tree without and don't want the |
||||||
|
# genesis task scanning in the background |
||||||
|
Application.load(:indexer) |
||||||
|
|
||||||
|
for application <- Application.spec(:indexer, :applications) do |
||||||
|
Application.ensure_all_started(application) |
||||||
|
end |
||||||
|
|
||||||
|
# no declared in :applications since it is test-only |
||||||
|
{:ok, _} = Application.ensure_all_started(:ex_machina) |
||||||
|
|
||||||
|
ExUnit.configure(formatters: [JUnitFormatter, ExUnit.CLIFormatter]) |
||||||
|
ExUnit.start() |
||||||
|
|
||||||
|
Ecto.Adapters.SQL.Sandbox.mode(Explorer.Repo, :manual) |
Loading…
Reference in new issue