From 2df87c2cd11373e187927bd0fa86263be9d519de Mon Sep 17 00:00:00 2001 From: William Sanches Date: Fri, 16 Nov 2018 11:35:00 -0200 Subject: [PATCH] Refactor metadata_updater to get interval on start --- apps/explorer/test/explorer/chain/token_test.exs | 2 +- apps/indexer/lib/indexer/token/metadata_updater.ex | 7 +++---- apps/indexer/lib/indexer/token/supervisor.ex | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/explorer/test/explorer/chain/token_test.exs b/apps/explorer/test/explorer/chain/token_test.exs index 57cf42d13a..0cab67ecff 100644 --- a/apps/explorer/test/explorer/chain/token_test.exs +++ b/apps/explorer/test/explorer/chain/token_test.exs @@ -6,7 +6,7 @@ defmodule Explorer.Chain.TokenTest do alias Explorer.Chain describe "cataloged_tokens/0" do - test "filters uncataloged tokens out" do + test "filters only cataloged tokens" do token = insert(:token, cataloged: true) insert(:token, cataloged: false) diff --git a/apps/indexer/lib/indexer/token/metadata_updater.ex b/apps/indexer/lib/indexer/token/metadata_updater.ex index 0606b0a0b5..b7135dd1e8 100644 --- a/apps/indexer/lib/indexer/token/metadata_updater.ex +++ b/apps/indexer/lib/indexer/token/metadata_updater.ex @@ -9,8 +9,8 @@ defmodule Indexer.Token.MetadataUpdater do alias Explorer.Chain.Token alias Explorer.Token.MetadataRetriever - def start_link(_) do - GenServer.start_link(__MODULE__, :ok, name: __MODULE__) + def start_link(initial_state) do + GenServer.start_link(__MODULE__, initial_state, name: __MODULE__) end @impl true @@ -25,8 +25,7 @@ defmodule Indexer.Token.MetadataUpdater do {:ok, tokens} = Chain.stream_cataloged_token_contract_address_hashes([], &(&2 ++ [&1])) update_metadata(tokens) - interval = Application.get_env(:indexer, :metadata_updater_days_interval) - Process.send_after(self(), :update_tokens, :timer.hours(interval) * 24) + Process.send_after(self(), :update_tokens, :timer.hours(state.update_interval) * 24) {:noreply, state} end diff --git a/apps/indexer/lib/indexer/token/supervisor.ex b/apps/indexer/lib/indexer/token/supervisor.ex index 6c51feffa2..d50184371b 100644 --- a/apps/indexer/lib/indexer/token/supervisor.ex +++ b/apps/indexer/lib/indexer/token/supervisor.ex @@ -27,11 +27,12 @@ defmodule Indexer.Token.Supervisor do @impl Supervisor def init(fetcher_arguments) do + metadata_updater_inverval = Application.get_env(:indexer, :metadata_updater_days_interval) Supervisor.init( [ {Task.Supervisor, name: Indexer.Token.TaskSupervisor}, {Fetcher, [fetcher_arguments, [name: Fetcher]]}, - {MetadataUpdater, [[], [name: MetadataUpdater]]} + {MetadataUpdater, %{update_interval: metadata_updater_inverval}} ], strategy: :one_for_one )