genserver that executes validator data imports every 24 hours

gsf-validator-metadata
Gustavo Santos Ferreira 6 years ago
parent add2b2c213
commit f2cbf37200
  1. 4
      apps/explorer/config/config.exs
  2. 3
      apps/explorer/lib/explorer/application.ex
  3. 31
      apps/explorer/lib/explorer/validator/metadata_processor.ex

@ -36,6 +36,10 @@ if System.get_env("METADATA_CONTRACT") && System.get_env("VALIDATORS_CONTRACT")
config :explorer, Explorer.Validator.MetadataRetriever, config :explorer, Explorer.Validator.MetadataRetriever,
metadata_contract_address: System.get_env("METADATA_CONTRACT"), metadata_contract_address: System.get_env("METADATA_CONTRACT"),
validators_contract_address: System.get_env("VALIDATORS_CONTRACT") validators_contract_address: System.get_env("VALIDATORS_CONTRACT")
config :explorer, Explorer.Validator.MetadataProcessor, enabled: true
else
config :explorer, Explorer.Validator.MetadataProcessor, enabled: false
end end
if System.get_env("SUPPLY_MODULE") == "TransactionAndLog" do if System.get_env("SUPPLY_MODULE") == "TransactionAndLog" do

@ -38,7 +38,8 @@ defmodule Explorer.Application do
configure(Explorer.Counters.TokenHoldersCounter), configure(Explorer.Counters.TokenHoldersCounter),
configure(Explorer.Counters.TokenTransferCounter), configure(Explorer.Counters.TokenTransferCounter),
configure(Explorer.Counters.BlockValidationCounter), configure(Explorer.Counters.BlockValidationCounter),
configure(Explorer.Counters.AddressesWithBalanceCounter) configure(Explorer.Counters.AddressesWithBalanceCounter),
configure(Explorer.Validator.MetadataProcessor)
] ]
|> List.flatten() |> List.flatten()
end end

@ -0,0 +1,31 @@
defmodule Explorer.Validator.MetadataProcessor do
@moduledoc """
module to periodically retrieve and update metadata belonging to validators
"""
use GenServer
alias Explorer.Validator.{MetadataImporter, MetadataRetriever}
def start_link(_) do
GenServer.start_link(__MODULE__, :ok, name: __MODULE__)
end
@impl true
def init(args) do
send(self(), :import_and_reschedule)
{:ok, args}
end
@impl true
def handle_info(:import_and_reschedule, state) do
MetadataRetriever.fetch_data()
|> MetadataImporter.import_metadata()
reschedule()
{:noreply, state}
end
defp reschedule do
Process.send_after(self(), :import_and_reschedule, :timer.hours(24))
end
end
Loading…
Cancel
Save