Now tx/day chart is collected once a day

pull/7242/head
Nikita Pozdniakov 2 years ago
parent 365f80b5cb
commit 00bbd11266
No known key found for this signature in database
GPG Key ID: F344106F9804FE5F
  1. 13
      apps/explorer/lib/explorer/history/process.ex
  2. 5
      apps/explorer/test/explorer/history/process_test.exs
  3. 3
      config/runtime.exs
  4. 1
      docker-compose/envs/common-blockscout.env
  5. 3
      docker/Makefile

@ -55,8 +55,7 @@ defmodule Explorer.History.Process do
end
defp schedule_next_compilation do
delay = config_or_default(:history_fetch_interval, :timer.minutes(60))
Process.send_after(self(), {:compile_historical_records, 2}, delay)
Process.send_after(self(), {:compile_historical_records, 2}, calculate_delay_until_next_midnight())
end
@spec failed_compilation(non_neg_integer(), module(), non_neg_integer()) :: any()
@ -108,4 +107,14 @@ defmodule Explorer.History.Process do
multiplier = Enum.reduce(2..failed_attempts, 1, fn _, acc -> 2 * acc end)
multiplier * base_backoff()
end
defp calculate_delay_until_next_midnight do
now = DateTime.utc_now()
# was added for testing possibility
time_to_fetch_at = config_or_default(:time_to_fetch_at, Time.new!(0, 0, 0, 0))
days_to_add = config_or_default(:days_to_add, 1)
tomorrow = DateTime.new!(Date.add(Date.utc_today(), days_to_add), time_to_fetch_at, now.time_zone)
DateTime.diff(tomorrow, now, :millisecond)
end
end

@ -61,7 +61,10 @@ defmodule Explorer.History.ProcessTest do
# ...but long enough to detect. 16ms should be detectable on the slowest dev machines
history_fetch_interval = 16
Application.put_env(:explorer, HistoryProcess, history_fetch_interval: history_fetch_interval)
now = DateTime.to_time(DateTime.utc_now())
time_to_fetch_at = now |> Time.add(history_fetch_interval, :millisecond)
days_to_add = if Time.compare(time_to_fetch_at, now) == :gt, do: 0, else: 1
Application.put_env(:explorer, HistoryProcess, time_to_fetch_at: time_to_fetch_at, days_to_add: days_to_add)
assert {:noreply, state} == HistoryProcess.handle_info({nil, {1, 0, {:ok, [record]}}}, state)

@ -266,9 +266,6 @@ config :explorer, Explorer.Chain.Transaction.History.Historian,
init_lag_milliseconds: ConfigHelper.parse_time_env_var("TXS_HISTORIAN_INIT_LAG", "0"),
days_to_compile_at_init: ConfigHelper.parse_integer_env_var("TXS_STATS_DAYS_TO_COMPILE_AT_INIT", 40)
config :explorer, Explorer.History.Process,
history_fetch_interval: ConfigHelper.parse_time_env_var("HISTORY_FETCH_INTERVAL", "1h")
if System.get_env("METADATA_CONTRACT") && System.get_env("VALIDATORS_CONTRACT") do
config :explorer, Explorer.Validator.MetadataRetriever,
metadata_contract_address: System.get_env("METADATA_CONTRACT"),

@ -117,7 +117,6 @@ DISABLE_EXCHANGE_RATES=true
ENABLE_TXS_STATS=true
SHOW_PRICE_CHART=false
SHOW_TXS_CHART=true
HISTORY_FETCH_INTERVAL=30
TXS_HISTORIAN_INIT_LAG=0
TXS_STATS_DAYS_TO_COMPILE_AT_INIT=10
COIN_BALANCE_HISTORY_DAYS=90

@ -252,9 +252,6 @@ endif
ifdef SHOW_TXS_CHART
BLOCKSCOUT_CONTAINER_PARAMS += -e 'SHOW_TXS_CHART=$(SHOW_TXS_CHART)'
endif
ifdef HISTORY_FETCH_INTERVAL
BLOCKSCOUT_CONTAINER_PARAMS += -e 'HISTORY_FETCH_INTERVAL=$(HISTORY_FETCH_INTERVAL)'
endif
ifdef TXS_HISTORIAN_INIT_LAG
BLOCKSCOUT_CONTAINER_PARAMS += -e 'TXS_HISTORIAN_INIT_LAG=$(TXS_HISTORIAN_INIT_LAG)'
endif

Loading…
Cancel
Save