Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/indexer/lib/indexer/buffered_task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,12 @@ defmodule Indexer.BufferedTask do
if state.flush_interval == :infinity do
state
else
# Keep one flush timer per worker. Overwriting a live reference leaves
# the previous timer running and starts another repeating flush chain.
if is_reference(state.flush_timer) do
Process.cancel_timer(state.flush_timer)
end

timer = Process.send_after(self(), :flush, state.flush_interval)
%__MODULE__{state | flush_timer: timer}
end
Expand Down
11 changes: 11 additions & 0 deletions apps/indexer/lib/indexer/fetcher/stats/hot_smart_contracts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ defmodule Indexer.Fetcher.Stats.HotSmartContracts do

Logger.info("Hot contracts fetched for #{date}")
else
{:error, {:error, :not_found}} ->
if Date.diff(Date.utc_today(), date) < @max_days_ago do
schedule_message_on_the_next_day({:fetch_for_date, date, false})
end

if new_day? do
schedule_next_day_fetch()
end

Logger.info("No indexed blocks for hot contracts on #{date}")

{:error, error} ->
Process.send_after(self(), {:fetch_for_date, date, new_day?}, @retry_interval)
Logger.error("Error fetching hot contracts for #{date}: #{inspect(error)}")
Expand Down
8 changes: 5 additions & 3 deletions apps/indexer/test/indexer/buffered_task_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ defmodule Indexer.BufferedTaskTest do

test "with 0 size without maximum size schedules next flush and hibernates" do
bound_queue = %BoundQueue{}
old_timer = Process.send_after(self(), :flush, :timer.minutes(5))

refute BoundQueue.shrunk?(bound_queue)

Expand All @@ -249,15 +250,16 @@ defmodule Indexer.BufferedTaskTest do
callback_module: ShrinkableTask,
callback_module_state: nil,
bound_queue: bound_queue,
flush_interval: 50,
flush_timer: nil,
flush_interval: :timer.minutes(5),
flush_timer: old_timer,
task_supervisor: BufferedTaskSup,
max_batch_size: 1,
max_concurrency: 1,
poll: false
})

refute flush_timer == nil
assert Process.read_timer(old_timer) == false
assert is_integer(Process.read_timer(flush_timer))
end

test "with 0 size with maximum size calls init/2 to get work that was shed before scheduling next flush and hibernates" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,19 @@ defmodule Indexer.Fetcher.Stats.HotSmartContractsTest do
end
end

test "logs an unavailable date without an error" do
insert(:block, number: 0, timestamp: DateTime.add(DateTime.utc_now(), -40, :day))
date = Date.add(Date.utc_today(), -1)

log =
capture_log([level: :info], fn ->
assert {:noreply, :ok} = HotSmartContracts.handle_info({:fetch_for_date, date, false}, :ok)
end)

assert log =~ "No indexed blocks for hot contracts on #{date}"
refute log =~ "Error fetching hot contracts"
end

describe "handle_continue/2" do
test "processes chain age check on startup" do
# Create blocks older than 30 days
Expand Down
Loading