Refactor metadata_updater to get interval on start

pull/1095/head
William Sanches 6 years ago
parent 8ee4e62087
commit 2df87c2cd1
No known key found for this signature in database
GPG Key ID: 27250E49FB133014
  1. 2
      apps/explorer/test/explorer/chain/token_test.exs
  2. 7
      apps/indexer/lib/indexer/token/metadata_updater.ex
  3. 3
      apps/indexer/lib/indexer/token/supervisor.ex

@ -6,7 +6,7 @@ defmodule Explorer.Chain.TokenTest do
alias Explorer.Chain alias Explorer.Chain
describe "cataloged_tokens/0" do describe "cataloged_tokens/0" do
test "filters uncataloged tokens out" do test "filters only cataloged tokens" do
token = insert(:token, cataloged: true) token = insert(:token, cataloged: true)
insert(:token, cataloged: false) insert(:token, cataloged: false)

@ -9,8 +9,8 @@ defmodule Indexer.Token.MetadataUpdater do
alias Explorer.Chain.Token alias Explorer.Chain.Token
alias Explorer.Token.MetadataRetriever alias Explorer.Token.MetadataRetriever
def start_link(_) do def start_link(initial_state) do
GenServer.start_link(__MODULE__, :ok, name: __MODULE__) GenServer.start_link(__MODULE__, initial_state, name: __MODULE__)
end end
@impl true @impl true
@ -25,8 +25,7 @@ defmodule Indexer.Token.MetadataUpdater do
{:ok, tokens} = Chain.stream_cataloged_token_contract_address_hashes([], &(&2 ++ [&1])) {:ok, tokens} = Chain.stream_cataloged_token_contract_address_hashes([], &(&2 ++ [&1]))
update_metadata(tokens) update_metadata(tokens)
interval = Application.get_env(:indexer, :metadata_updater_days_interval) Process.send_after(self(), :update_tokens, :timer.hours(state.update_interval) * 24)
Process.send_after(self(), :update_tokens, :timer.hours(interval) * 24)
{:noreply, state} {:noreply, state}
end end

@ -27,11 +27,12 @@ defmodule Indexer.Token.Supervisor do
@impl Supervisor @impl Supervisor
def init(fetcher_arguments) do def init(fetcher_arguments) do
metadata_updater_inverval = Application.get_env(:indexer, :metadata_updater_days_interval)
Supervisor.init( Supervisor.init(
[ [
{Task.Supervisor, name: Indexer.Token.TaskSupervisor}, {Task.Supervisor, name: Indexer.Token.TaskSupervisor},
{Fetcher, [fetcher_arguments, [name: Fetcher]]}, {Fetcher, [fetcher_arguments, [name: Fetcher]]},
{MetadataUpdater, [[], [name: MetadataUpdater]]} {MetadataUpdater, %{update_interval: metadata_updater_inverval}}
], ],
strategy: :one_for_one strategy: :one_for_one
) )

Loading…
Cancel
Save