From 7a67a98fa65941364e842a21b64ac316d2d0c42c Mon Sep 17 00:00:00 2001 From: Viktor Baranov Date: Tue, 11 Jul 2023 18:19:44 +0300 Subject: [PATCH] Resolve warning: Application.get_env/2 is discouraged in the module body, use Application.compile_env/3 instead lib/indexer/memory/monitor.ex:17: Indexer.Memory.Monitor --- CHANGELOG.md | 1 + apps/indexer/lib/indexer/memory/monitor.ex | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c43423bb86..c324740912 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ ### Chore - [#7901](https://github.com/blockscout/blockscout/pull/7901) - Fix Docker image build +- [#7890](https://github.com/blockscout/blockscout/pull/7890) - Resolve warning: Application.get_env/2 is discouraged in the module body, use Application.compile_env/3 instead - [#7863](https://github.com/blockscout/blockscout/pull/7863) - Add max_age for account sessions - [#7841](https://github.com/blockscout/blockscout/pull/7841) - CORS setup for docker-compose config with new frontend - [#7832](https://github.com/blockscout/blockscout/pull/7832), [#7891](https://github.com/blockscout/blockscout/pull/7891) - API v2: Add block_number, block_hash to logs diff --git a/apps/indexer/lib/indexer/memory/monitor.ex b/apps/indexer/lib/indexer/memory/monitor.ex index 40562a0f13..a979ee6591 100644 --- a/apps/indexer/lib/indexer/memory/monitor.ex +++ b/apps/indexer/lib/indexer/memory/monitor.ex @@ -14,8 +14,7 @@ defmodule Indexer.Memory.Monitor do alias Indexer.Memory.Shrinkable - defstruct limit: Application.get_env(:indexer, :memory_limit), - timer_interval: :timer.minutes(1), + defstruct timer_interval: :timer.minutes(1), timer_reference: nil, shrinkable_set: MapSet.new() @@ -62,11 +61,11 @@ defmodule Indexer.Memory.Monitor do end @impl GenServer - def handle_info(:check, %__MODULE__{limit: limit} = state) do + def handle_info(:check, state) do total = :erlang.memory(:total) - if limit < total do - log_memory(%{limit: limit, total: total}) + if memory_limit() < total do + log_memory(%{limit: memory_limit(), total: total}) shrink_or_log(state) end @@ -169,4 +168,8 @@ defmodule Indexer.Memory.Monitor do |> Enum.map(fn pid -> {pid, memory(pid)} end) |> Enum.sort_by(&elem(&1, 1), &>=/2) end + + defp memory_limit do + Application.get_env(:indexer, :memory_limit) + end end