Skip to content

Commit 5427a7a

Browse files
authored
Keep caches alive in case of postgres unavailability (#4974)
1 parent 3abf974 commit 5427a7a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/plausible/cache.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ defmodule Plausible.Cache do
6262
@modes [:all, :updated_recently]
6363

6464
alias Plausible.Cache.Adapter
65+
require Logger
6566

6667
@spec get(any(), Keyword.t()) :: any() | nil
6768
def get(key, opts \\ []) when is_list(opts) do
@@ -182,8 +183,13 @@ defmodule Plausible.Cache do
182183
Plausible.PromEx.Plugins.PlausibleMetrics.measure_duration(
183184
telemetry_event_refresh(cache_name, mode),
184185
fn ->
185-
items = repo().all(query)
186-
:ok = merge_items(items, opts)
186+
try do
187+
items = repo().all(query)
188+
:ok = merge_items(items, opts)
189+
catch
190+
_, e ->
191+
Logger.error("Error refreshing '#{cache_name}' - #{inspect(e)}")
192+
end
187193
end
188194
)
189195

0 commit comments

Comments
 (0)