Merge pull request #3265 from poanetwork/vb-possibility-to-set-token-updater-min-interval

Open possibility to set token metadata updater interval less than hour
pull/3269/head
Victor Baranov 4 years ago committed by GitHub
commit 31a907ff34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      apps/explorer/lib/explorer/chain.ex
  2. 6
      apps/explorer/lib/explorer/chain/token.ex
  3. 4
      apps/indexer/lib/indexer/fetcher/token_updater.ex

@ -3538,9 +3538,9 @@ defmodule Explorer.Chain do
reducer :: (entry :: Hash.Address.t(), accumulator -> accumulator) reducer :: (entry :: Hash.Address.t(), accumulator -> accumulator)
) :: {:ok, accumulator} ) :: {:ok, accumulator}
when accumulator: term() when accumulator: term()
def stream_cataloged_token_contract_address_hashes(initial, reducer, hours_ago_updated \\ 48) def stream_cataloged_token_contract_address_hashes(initial, reducer, some_time_ago_updated \\ 2880)
when is_function(reducer, 2) do when is_function(reducer, 2) do
hours_ago_updated some_time_ago_updated
|> Token.cataloged_tokens() |> Token.cataloged_tokens()
|> order_by(asc: :updated_at) |> order_by(asc: :updated_at)
|> Repo.stream_reduce(initial, reducer) |> Repo.stream_reduce(initial, reducer)

@ -107,14 +107,14 @@ defmodule Explorer.Chain.Token do
These are tokens with cataloged field set to true and updated_at is earlier or equal than an hour ago. These are tokens with cataloged field set to true and updated_at is earlier or equal than an hour ago.
""" """
def cataloged_tokens(hours \\ 48) do def cataloged_tokens(minutes \\ 2880) do
date_now = DateTime.utc_now() date_now = DateTime.utc_now()
hours_ago_date = DateTime.add(date_now, -:timer.hours(hours), :millisecond) some_time_ago_date = DateTime.add(date_now, -:timer.minutes(minutes), :millisecond)
from( from(
token in __MODULE__, token in __MODULE__,
select: token.contract_address_hash, select: token.contract_address_hash,
where: token.cataloged == true and token.updated_at <= ^hours_ago_date where: token.cataloged == true and token.updated_at <= ^some_time_ago_date
) )
end end
end end

@ -44,9 +44,9 @@ defmodule Indexer.Fetcher.TokenUpdater do
@impl BufferedTask @impl BufferedTask
def init(initial, reducer, _) do def init(initial, reducer, _) do
metadata_updater_inverval = Application.get_env(:indexer, :metadata_updater_seconds_interval) metadata_updater_inverval = Application.get_env(:indexer, :metadata_updater_seconds_interval)
hour_interval = Kernel.round(metadata_updater_inverval / (60 * 60)) interval_in_minutes = Kernel.round(metadata_updater_inverval / 60)
{:ok, tokens} = Chain.stream_cataloged_token_contract_address_hashes(initial, reducer, hour_interval) {:ok, tokens} = Chain.stream_cataloged_token_contract_address_hashes(initial, reducer, interval_in_minutes)
tokens tokens
end end

Loading…
Cancel
Save