Allow offline fetching for the ChainStatistics server

pull/3/head
Doc Ritezel 7 years ago
parent 37e2798f28
commit 081e9ecf08
  1. 7
      lib/explorer/application.ex
  2. 7
      lib/explorer/servers/chain_statistics.ex

@ -26,7 +26,11 @@ defmodule Explorer.Application do
defp children(_) do defp children(_) do
import Supervisor.Spec import Supervisor.Spec
exq_options = [] |> Keyword.put(:mode, :enqueuer) exq_options = [] |> Keyword.put(:mode, :enqueuer)
[supervisor(Exq, [exq_options]) | children()] [
supervisor(Exq, [exq_options]),
worker(Explorer.Servers.ChainStatistics, [])
| children()
]
end end
defp children do defp children do
@ -34,7 +38,6 @@ defmodule Explorer.Application do
[ [
supervisor(Explorer.Repo, []), supervisor(Explorer.Repo, []),
supervisor(ExplorerWeb.Endpoint, []), supervisor(ExplorerWeb.Endpoint, []),
worker(Explorer.Servers.ChainStatistics, [])
] ]
end end
end end

@ -7,7 +7,12 @@ defmodule Explorer.Servers.ChainStatistics do
@interval 1_000 @interval 1_000
def fetch, do: GenServer.call(__MODULE__, :fetch) def fetch do
case GenServer.whereis(__MODULE__) do
nil -> Chain.fetch()
pid -> GenServer.call(pid, :fetch)
end
end
def start_link, do: start_link(%Chain{}) def start_link, do: start_link(%Chain{})
def start_link(%Chain{} = chain) do def start_link(%Chain{} = chain) do
GenServer.start_link(__MODULE__, chain, name: __MODULE__) GenServer.start_link(__MODULE__, chain, name: __MODULE__)

Loading…
Cancel
Save