diff --git a/lib/zcash_explorer/application.ex b/lib/zcash_explorer/application.ex index 98bca5e..11fc210 100644 --- a/lib/zcash_explorer/application.ex +++ b/lib/zcash_explorer/application.ex @@ -38,7 +38,8 @@ defmodule ZcashExplorer.Application do warmer(module: ZcashExplorer.Blocks.BlockWarmer, state: {}), warmer(module: ZcashExplorer.Transactions.TransactionWarmer, state: {}), warmer(module: ZcashExplorer.Mempool.MempoolWarmer, state: {}), - warmer(module: ZcashExplorer.Nodes.NodeWarmer, state: {}) + warmer(module: ZcashExplorer.Nodes.NodeWarmer, state: {}), + warmer(module: ZcashExplorer.Metrics.InfoWarmer, state: {}) ]} ] diff --git a/lib/zcash_explorer/metrics/info_warmer.ex b/lib/zcash_explorer/metrics/info_warmer.ex new file mode 100644 index 0000000..b2a64c6 --- /dev/null +++ b/lib/zcash_explorer/metrics/info_warmer.ex @@ -0,0 +1,24 @@ +defmodule ZcashExplorer.Metrics.InfoWarmer do + use Cachex.Warmer + + @doc """ + Returns the interval for this warmer. + """ + def interval, + do: :timer.seconds(60) + + @doc """ + Executes this cache warmer. + """ + def execute(_state) do + Zcashex.getinfo() |> handle_result() + end + + # ignores the warmer result in case of error + defp handle_result({:error, _reason}), + do: :ignore + + defp handle_result({:ok, info}) do + {:ok, [{"info", info}]} + end +end diff --git a/lib/zcash_explorer_web/live/blockchain_info_live.ex b/lib/zcash_explorer_web/live/blockchain_info_live.ex index 91a702d..7396831 100644 --- a/lib/zcash_explorer_web/live/blockchain_info_live.ex +++ b/lib/zcash_explorer_web/live/blockchain_info_live.ex @@ -51,7 +51,14 @@ defmodule ZcashExplorerWeb.BlockChainInfoLive do - +
+
+ zcashd version +
+
+ <%= @blockchain_info["build"] %> +
+
@@ -65,6 +72,8 @@ defmodule ZcashExplorerWeb.BlockChainInfoLive do case Cachex.get(:app_cache, "metrics") do {:ok, info} -> + {:ok, %{"build" => build}} = Cachex.get(:app_cache, "info") + info = Map.put(info, "build", build) {:ok, assign(socket, :blockchain_info, info)} {:error, _reason} -> @@ -76,6 +85,8 @@ defmodule ZcashExplorerWeb.BlockChainInfoLive do def handle_info(:update, socket) do Process.send_after(self(), :update, 15000) {:ok, info} = Cachex.get(:app_cache, "metrics") + {:ok, %{"build" => build}} = Cachex.get(:app_cache, "info") + info = Map.put(info, "build", build) {:noreply, assign(socket, :blockchain_info, info)} end