Add runner-specific options

staking
Vadim 5 years ago committed by Victor Baranov
parent be423d3966
commit 598673fb0a
  1. 16
      apps/explorer/lib/explorer/chain/import.ex
  2. 7
      apps/explorer/lib/explorer/chain/import/runner.ex
  3. 3
      apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex
  4. 3
      apps/explorer/lib/explorer/chain/import/runner/staking_pools_delegators.ex

@ -3,8 +3,6 @@ defmodule Explorer.Chain.Import do
Bulk importing of data into `Explorer.Repo`
"""
require Logger
alias Ecto.Changeset
alias Explorer.Chain.Events.Publisher
alias Explorer.Chain.Import
@ -231,8 +229,15 @@ defmodule Explorer.Chain.Import do
defp validate_runner_options(runner, options) when is_map(options) do
option_key = runner.option_key()
runner_specific_options =
if Map.has_key?(Enum.into(runner.__info__(:functions), %{}), :runner_specific_options) do
apply(runner, :runner_specific_options, [])
else
[]
end
case {validate_runner_option_params_required(option_key, options),
validate_runner_options_known(option_key, options)} do
validate_runner_options_known(option_key, options, runner_specific_options)} do
{:ignore, :ok} -> :ignore
{:ignore, {:error, _} = error} -> error
{:ok, :ok} -> {:ok, {runner, options}}
@ -252,10 +257,11 @@ defmodule Explorer.Chain.Import do
defp validate_runner_option_params_required(runner_option_key, _),
do: {:error, {:required, [runner_option_key, :params]}}
@local_options ~w(on_conflict params with timeout clear_snapshotted_values)a
@local_options ~w(on_conflict params with timeout)a
defp validate_runner_options_known(runner_option_key, options) do
defp validate_runner_options_known(runner_option_key, options, runner_specific_options) do
unknown_option_keys = Map.keys(options) -- @local_options
unknown_option_keys = unknown_option_keys -- runner_specific_options
if Enum.empty?(unknown_option_keys) do
:ok

@ -51,4 +51,11 @@ defmodule Explorer.Chain.Import.Runner do
@callback run(Multi.t(), changes_list, %{optional(atom()) => term()}) :: Multi.t()
# @callback run_insert_only(Multi.t(), changes_list, %{optional(atom()) => term()}) :: Multi.t()
@callback timeout() :: timeout()
@doc """
The optional list of runner-specific options.
"""
@callback runner_specific_options() :: [atom()]
@optional_callbacks runner_specific_options: 0
end

@ -23,6 +23,9 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do
@impl Import.Runner
def option_key, do: :staking_pools
@impl Import.Runner
def runner_specific_options, do: [:clear_snapshotted_values]
@impl Import.Runner
def imported_table_row do
%{

@ -24,6 +24,9 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsDelegators do
@impl Import.Runner
def option_key, do: :staking_pools_delegators
@impl Import.Runner
def runner_specific_options, do: [:clear_snapshotted_values]
@impl Import.Runner
def imported_table_row do
%{

Loading…
Cancel
Save