peburrows / goth

Elixir package for Oauth authentication via Google Cloud APIs
http://hexdocs.pm/goth
MIT License
284 stars 108 forks source link

Change from Backoff module to a simple function API #140

Closed aleDsz closed 2 years ago

aleDsz commented 2 years ago

With this new change, we will allow the :backoff option to be a to be a fun/1 which receives the current retry count from the :retries key from Goth struct:

fun = fn retry_count ->
  retry_count * 1000
end

{:ok, _pid} = Goth.start_link(name: Goth.Default, backoff: fun)

We will use a default exponential backoff if you don't pass :backoff option to Goth.start_link/1:

defp exp_backoff(retry_count) do
  Integer.pow(2, retry_count) * 1000
end

Also, now the retry count (:retries) will start from 0, so we can execute the retry delay calculation from the current retry count.

wojtekmach commented 2 years ago

Thank you!