Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry option error: function true.wait_for/2 is undefined (module true is not available) #70

Open
qgadrian opened this issue Jul 12, 2023 · 0 comments

Comments

@qgadrian
Copy link

hello!

There is a bug in the current code for the retry options.
Currently, the retry option is typed in the %Opts{} struct as a boolean | module, but this fails when the value is a boolean (see the bug in this line).

Can you please fix it?
Otherwise, I can create a PR to get it fixed but before spending time on it I will need to know your idea for this retry option... is the boolean type deprecated? which default value should be preferred?

My initial approach would be something like (disclaimer, this code won't work it's just to get the idea)

  defp do_retry(result, request, opts) do
    attempt = Map.get(request.private, :attempt, 1)

    max_attempts = Keyword.get(opts.retry_opts, :max_attempts, 3)

    if max_attempts >= attempt do
      seconds_to_wait = seconds_to_wait(opts)

      :timer.sleep(seconds_to_wait)

      request
      |> Map.put(:private, Map.put(request.private, :attempt, attempt + 1))
      |> do_send(opts)
    else
      {:error, result}
    end
  end

  defp seconds_to_wait(retry: retry) when is_boolean(retry) do
    @whatever_default_wait
  end

  defp seconds_to_wait(retry: retry) when is_module(retry) do
    opts.wait_for(request, opts)
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant