diff --git a/apps/explorer/config/config.exs b/apps/explorer/config/config.exs index 4cabe0c008..c58234ec9b 100644 --- a/apps/explorer/config/config.exs +++ b/apps/explorer/config/config.exs @@ -36,6 +36,10 @@ if System.get_env("METADATA_CONTRACT") && System.get_env("VALIDATORS_CONTRACT") config :explorer, Explorer.Validator.MetadataRetriever, metadata_contract_address: System.get_env("METADATA_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 if System.get_env("SUPPLY_MODULE") == "TransactionAndLog" do diff --git a/apps/explorer/lib/explorer/application.ex b/apps/explorer/lib/explorer/application.ex index bf124baa35..1f088a6578 100644 --- a/apps/explorer/lib/explorer/application.ex +++ b/apps/explorer/lib/explorer/application.ex @@ -38,7 +38,8 @@ defmodule Explorer.Application do configure(Explorer.Counters.TokenHoldersCounter), configure(Explorer.Counters.TokenTransferCounter), configure(Explorer.Counters.BlockValidationCounter), - configure(Explorer.Counters.AddressesWithBalanceCounter) + configure(Explorer.Counters.AddressesWithBalanceCounter), + configure(Explorer.Validator.MetadataProcessor) ] |> List.flatten() end diff --git a/apps/explorer/lib/explorer/validator/metadata_processor.ex b/apps/explorer/lib/explorer/validator/metadata_processor.ex new file mode 100644 index 0000000000..ebc9db9d46 --- /dev/null +++ b/apps/explorer/lib/explorer/validator/metadata_processor.ex @@ -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