Skip to content

Commit

Permalink
feat: add a minimum polling interval to protect from overrun
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Jan 18, 2019
1 parent ffcdcb6 commit ec6c24e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion apps/indexer/lib/indexer/block/realtime/fetcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ defmodule Indexer.Block.Realtime.Fetcher do

@behaviour Block.Fetcher

@minimum_safe_polling_period :timer.seconds(10)

@enforce_keys ~w(block_fetcher)a
defstruct ~w(block_fetcher subscription previous_number max_number_seen timer)a

Expand Down Expand Up @@ -140,7 +142,9 @@ defmodule Indexer.Block.Realtime.Fetcher do
block_time -> round(Duration.to_milliseconds(block_time) * 2)
end

Process.send_after(self(), :poll_latest_block_number, polling_period)
safe_polling_period = max(polling_period, @minimum_safe_polling_period)

Process.send_after(self(), :poll_latest_block_number, safe_polling_period)
end

@import_options ~w(address_hash_to_fetched_balance_block_number)a
Expand Down

0 comments on commit ec6c24e

Please sign in to comment.