Skip to content

Commit

Permalink
feat: make replaced transactions disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Feb 14, 2019
1 parent 5b5a0b3 commit c97ce0c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions apps/indexer/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ config :indexer,
# bytes
memory_limit: 1 <<< 30

# config :indexer, Indexer.ReplacedTransaction.Supervisor, disabled?: true

config :indexer, Indexer.Tracer,
service: :indexer,
adapter: SpandexDatadog.Adapter,
Expand Down
10 changes: 7 additions & 3 deletions apps/indexer/lib/indexer/replaced_transaction/fetcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule Indexer.ReplacedTransaction.Fetcher do
alias Explorer.Chain
alias Explorer.Chain.Hash
alias Indexer.{BufferedTask, Tracer}
alias Indexer.ReplacedTransaction.Supervisor, as: ReplacedTransactionSupervisor

@behaviour BufferedTask

Expand All @@ -31,9 +32,12 @@ defmodule Indexer.ReplacedTransaction.Fetcher do
}
]) :: :ok
def async_fetch(transactions_fields, timeout \\ 5000) when is_list(transactions_fields) do
entries = Enum.map(transactions_fields, &entry/1)

BufferedTask.buffer(__MODULE__, entries, timeout)
if ReplacedTransactionSupervisor.disabled?() do
:ok
else
entries = Enum.map(transactions_fields, &entry/1)
BufferedTask.buffer(__MODULE__, entries, timeout)
end
end

@doc false
Expand Down
10 changes: 9 additions & 1 deletion apps/indexer/lib/indexer/replaced_transaction/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ defmodule Indexer.ReplacedTransaction.Supervisor do
end

def start_link(arguments, gen_server_options \\ []) do
Supervisor.start_link(__MODULE__, arguments, Keyword.put_new(gen_server_options, :name, __MODULE__))
if disabled?() do
:ignore
else
Supervisor.start_link(__MODULE__, arguments, Keyword.put_new(gen_server_options, :name, __MODULE__))
end
end

def disabled?() do
Application.get_env(:indexer, __MODULE__, [])[:disabled?] == true
end

@impl Supervisor
Expand Down

0 comments on commit c97ce0c

Please sign in to comment.