|
|
@ -16,11 +16,13 @@ defmodule Explorer.Chain.Cache.AddressSum do |
|
|
|
alias Explorer.Chain |
|
|
|
alias Explorer.Chain |
|
|
|
|
|
|
|
|
|
|
|
defp handle_fallback(:sum) do |
|
|
|
defp handle_fallback(:sum) do |
|
|
|
# This will get the task PID if one exists and launch a new task if not |
|
|
|
result = fetch_from_db() |
|
|
|
# See next `handle_fallback` definition |
|
|
|
|
|
|
|
get_async_task() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{:return, nil} |
|
|
|
if Application.get_env(:explorer, __MODULE__)[:enabled] do |
|
|
|
|
|
|
|
{:update, result} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{:return, result} |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp handle_fallback(:async_task) do |
|
|
|
defp handle_fallback(:async_task) do |
|
|
@ -29,7 +31,7 @@ defmodule Explorer.Chain.Cache.AddressSum do |
|
|
|
{:ok, task} = |
|
|
|
{:ok, task} = |
|
|
|
Task.start(fn -> |
|
|
|
Task.start(fn -> |
|
|
|
try do |
|
|
|
try do |
|
|
|
result = Chain.fetch_sum_coin_total_supply() |
|
|
|
result = fetch_from_db() |
|
|
|
|
|
|
|
|
|
|
|
set_sum(result) |
|
|
|
set_sum(result) |
|
|
|
rescue |
|
|
|
rescue |
|
|
@ -45,6 +47,10 @@ defmodule Explorer.Chain.Cache.AddressSum do |
|
|
|
{:update, task} |
|
|
|
{:update, task} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp fetch_from_db do |
|
|
|
|
|
|
|
Chain.fetch_sum_coin_total_supply() |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
# By setting this as a `callback` an async task will be started each time the |
|
|
|
# By setting this as a `callback` an async task will be started each time the |
|
|
|
# `sum` expires (unless there is one already running) |
|
|
|
# `sum` expires (unless there is one already running) |
|
|
|
defp async_task_on_deletion({:delete, _, :sum}), do: get_async_task() |
|
|
|
defp async_task_on_deletion({:delete, _, :sum}), do: get_async_task() |
|
|
|