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
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)

@ -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

@ -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
)

Loading…
Cancel
Save