fix: Fix Retry NFT fetcher (#10146)

pull/10174/head
nikitosing 6 months ago committed by GitHub
parent d3e15d3379
commit 034bc181b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      apps/explorer/lib/explorer/chain.ex
  2. 31
      apps/indexer/test/indexer/fetcher/token_instance/helper_test.exs

@ -3707,7 +3707,7 @@ defmodule Explorer.Chain do
Instance
|> where([instance], not is_nil(instance.error))
|> where([instance], is_nil(instance.refetch_after) or instance.refetch_after > ^DateTime.utc_now())
|> where([instance], is_nil(instance.refetch_after) or instance.refetch_after < ^DateTime.utc_now())
|> select([instance], %{
contract_address_hash: instance.token_contract_address_hash,
token_id: instance.token_id
@ -3918,6 +3918,8 @@ defmodule Explorer.Chain do
base = config[:exp_timeout_base]
max_refetch_interval = config[:max_refetch_interval]
max_retry_count = :math.log(max_refetch_interval / 1000 / coef) / :math.log(base)
from(
token_instance in Instance,
update: [
@ -3934,7 +3936,7 @@ defmodule Explorer.Chain do
fragment(
"""
CASE WHEN EXCLUDED.metadata IS NULL THEN
NOW() AT TIME ZONE 'UTC' + LEAST(interval '1 seconds' * (? * ? ^ (? + 1)), interval '1 milliseconds' * ?)
NOW() AT TIME ZONE 'UTC' + interval '1 seconds' * (? * ? ^ LEAST(? + 1.0, ?))
ELSE
NULL
END
@ -3942,7 +3944,7 @@ defmodule Explorer.Chain do
^coef,
^base,
token_instance.retries_count,
^max_refetch_interval
^max_retry_count
)
]
],

@ -520,5 +520,36 @@ defmodule Indexer.Fetcher.TokenInstance.HelperTest do
"https://ipfs.io/ipfs/QmU6DGXciSZXTH1fUKkEqj74P8FeXPRKxSTjgRsVKUQa95/base/300067000000000000.JPG"
}
end
test "Don't fail on high retries count" do
config = Application.get_env(:indexer, Indexer.Fetcher.TokenInstance.Retry)
coef = config[:exp_timeout_coeff]
base = config[:exp_timeout_base]
max_refetch_interval = config[:max_refetch_interval]
erc_721_token = insert(:token, type: "ERC-721")
token_instance =
insert(:token_instance,
token_contract_address_hash: erc_721_token.contract_address_hash,
error: "error",
metadata: nil,
retries_count: 50
)
Helper.batch_fetch_instances([
%{contract_address_hash: token_instance.token_contract_address_hash, token_id: token_instance.token_id}
])
now = DateTime.utc_now()
refetch_after = DateTime.add(now, max_refetch_interval, :millisecond)
[instance] = Repo.all(Instance)
assert instance.retries_count == 51
assert DateTime.diff(refetch_after, instance.refetch_after) < 1
assert !is_nil(instance.error)
end
end
end

Loading…
Cancel
Save