Skip to content

Commit

Permalink
feat(Skate.Warmup): More logging for failed queries (#2157)
Browse files Browse the repository at this point in the history
* feat(Skate.Warmup): More logging for failed queries

* chore(Skate.Warmup): update retry configuration
  • Loading branch information
KaylaBrady authored Jul 31, 2023
1 parent a78e007 commit 7738e80
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ config :skate, Skate.Repo,

config :skate, Skate.WarmUp,
minimum_percent_queries_to_succeed: 0.6,
max_attempts: 5,
seconds_between_attempts: 3
max_attempts: 20,
seconds_between_attempts: 1

config :laboratory,
features: [
Expand Down
18 changes: 16 additions & 2 deletions lib/skate/warm_up.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ defmodule Skate.WarmUp do
seconds_between_attempts = warmup_config[:seconds_between_attempts] || 0

warm_up_check_fn =
Application.get_env(:skate, :warm_up_test_fn, fn _index, _attemptgit ->
Skate.Repo.query("SELECT 1", [])
Application.get_env(:skate, :warm_up_test_fn, fn index, attempt ->
attempt_query(index, attempt)
end)

case check_connections_warmed_up(%{
Expand All @@ -39,6 +39,20 @@ defmodule Skate.WarmUp do
end
end

defp attempt_query(index, attempt) do
case Skate.Repo.query("SELECT 1", []) do
{:ok, result} ->
{:ok, result}

{:error, error} ->
Logger.warn(
"#{__MODULE__} warmup query failed. attempt=#{attempt} query_number=#{index} reason=#{inspect(error)}"
)

{:error, error}
end
end

defp check_connections_warmed_up(
%{
pool_size: pool_size,
Expand Down

0 comments on commit 7738e80

Please sign in to comment.