From e9b65034bad337c67f44edfcaa0f1223fa999093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Vila=C3=A7a?= Date: Mon, 25 Aug 2025 10:29:21 -0300 Subject: [PATCH 1/5] handle retry callback --- lib/goth.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/goth.ex b/lib/goth.ex index 6e41f22..5430e49 100644 --- a/lib/goth.ex +++ b/lib/goth.ex @@ -104,6 +104,7 @@ defmodule Goth do |> Keyword.put_new(:http_client, {:finch, []}) |> Keyword.put_new(:source, {:default, []}) |> Keyword.put_new(:retry_delay, &exp_backoff/1) + |> Keyword.put_new(:handle_retry_callback, &handle_retry_callback/2) name = Keyword.fetch!(opts, :name) GenServer.start_link(__MODULE__, opts, name: registry_name(name)) @@ -151,6 +152,7 @@ defmodule Goth do :name, :source, :retry_delay, + :handle_retry_callback, :http_client, :retry_after, :refresh_before, @@ -250,7 +252,9 @@ defmodule Goth do raise "too many failed attempts to refresh, last error: #{inspect(exception)}" end - defp handle_retry(_, state) do + defp handle_retry(exception, state) do + state.handle_retry_callback(exception, state) + state = %{state | retries: state.retries + 1} time_in_milliseconds = state.retry_delay.(state.retries) Process.send_after(self(), :refresh, time_in_milliseconds) @@ -276,6 +280,8 @@ defmodule Goth do min(30, round(:math.pow(2, retry_count))) * 1000 end + def handle_retry_callback(exception, state), do: :ok + defp put(name, token) do Registry.update_value(@registry, name, fn _ -> token end) end From e7c2d390d01690d78866c3e5191e8b7c120efe66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Vila=C3=A7a?= Date: Mon, 25 Aug 2025 10:46:18 -0300 Subject: [PATCH 2/5] fix function call and visibility of default function --- lib/goth.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/goth.ex b/lib/goth.ex index 5430e49..8fb5825 100644 --- a/lib/goth.ex +++ b/lib/goth.ex @@ -253,7 +253,7 @@ defmodule Goth do end defp handle_retry(exception, state) do - state.handle_retry_callback(exception, state) + state.handle_retry_callback.(exception, state) state = %{state | retries: state.retries + 1} time_in_milliseconds = state.retry_delay.(state.retries) @@ -280,7 +280,7 @@ defmodule Goth do min(30, round(:math.pow(2, retry_count))) * 1000 end - def handle_retry_callback(exception, state), do: :ok + defp handle_retry_callback(_exception, _state), do: :ok defp put(name, token) do Registry.update_value(@registry, name, fn _ -> token end) From 30355801cda74a7ccd539334e3947f79753ec50a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Vila=C3=A7a?= Date: Mon, 25 Aug 2025 11:04:02 -0300 Subject: [PATCH 3/5] inspect struct --- lib/goth.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/goth.ex b/lib/goth.ex index 8fb5825..5f8cf3c 100644 --- a/lib/goth.ex +++ b/lib/goth.ex @@ -175,6 +175,7 @@ defmodule Goth do {prefetch, opts} = Keyword.pop(opts, :prefetch, :async) state = struct!(__MODULE__, opts) + |> IO.inspect() state = Map.update!(state, :http_client, &start_http_client/1) case prefetch do From 7aab22af09f4bc0d1bb94689e68b278a7f02992a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Vila=C3=A7a?= Date: Mon, 25 Aug 2025 11:09:26 -0300 Subject: [PATCH 4/5] inspect --- lib/goth.ex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/goth.ex b/lib/goth.ex index 5f8cf3c..63488e4 100644 --- a/lib/goth.ex +++ b/lib/goth.ex @@ -175,7 +175,6 @@ defmodule Goth do {prefetch, opts} = Keyword.pop(opts, :prefetch, :async) state = struct!(__MODULE__, opts) - |> IO.inspect() state = Map.update!(state, :http_client, &start_http_client/1) case prefetch do @@ -254,7 +253,9 @@ defmodule Goth do end defp handle_retry(exception, state) do - state.handle_retry_callback.(exception, state) + # state.handle_retry_callback.(exception, state) + IO.inspect(exception) + IO.inspect(state) state = %{state | retries: state.retries + 1} time_in_milliseconds = state.retry_delay.(state.retries) From 390504372b5851aa25a68d47d6bc9bf61f4d0a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Vila=C3=A7a?= Date: Mon, 25 Aug 2025 11:14:02 -0300 Subject: [PATCH 5/5] fix call --- lib/goth.ex | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/goth.ex b/lib/goth.ex index 63488e4..8fb5825 100644 --- a/lib/goth.ex +++ b/lib/goth.ex @@ -253,9 +253,7 @@ defmodule Goth do end defp handle_retry(exception, state) do - # state.handle_retry_callback.(exception, state) - IO.inspect(exception) - IO.inspect(state) + state.handle_retry_callback.(exception, state) state = %{state | retries: state.retries + 1} time_in_milliseconds = state.retry_delay.(state.retries)