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

feat: set default maximum retry to zero #35

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ config :novu,
domain: "domain", # required: your domain
wait_min: 1000, # optional: the minimum time to retry a request is milliseconds (default: 1000)
wait_max: 10_000, # optional: the maximum time to retry a request is milliseconds (default: 10_000)
max_retries: 3, # optional: the amount of retries in case of responses 408/429/500/502/503/504 (default: 3)
max_retries: 3, # optional: the amount of retries in case of responses 408/429/500/502/503/504 (default: 0)
retry_log_level: :warning # optional: the log level to emit retry logs at. Can be set to false do disable logging (default: :warning)
```

Expand Down
4 changes: 3 additions & 1 deletion lib/novu/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ defmodule Novu.Http do

@type response() :: {:ok, map()} | {:error, list() | :timeout | any()}

@max_retries 0

@doc """
Makes a `DELETE` request to Novu.
"""
Expand Down Expand Up @@ -81,7 +83,7 @@ defmodule Novu.Http do

defp wait_min, do: Application.get_env(:novu, :wait_min, 1000)
defp wait_max, do: Application.get_env(:novu, :wait_max, 10_000)
defp max_retries, do: Application.get_env(:novu, :max_retries, 3)
defp max_retries, do: Application.get_env(:novu, :max_retries, @max_retries)
defp retry_log_level, do: Application.get_env(:novu, :retry_log_level, :warning)

defp retry_delay_function(n) do
Expand Down
12 changes: 12 additions & 0 deletions test/novu/http_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ defmodule Novu.HttpTest do
end

describe "build_req/1" do
test "default maximum retry should be zero", %{bypass: bypass} do
wait_min = 100
Application.put_env(:novu, :wait_min, wait_min)
Application.delete_env(:novu, :max_retries)

Bypass.expect_once(bypass, "GET", "/", fn conn ->
novu_response(conn, 500, %{data: %{error: "Internal Server Error"}})
end)

Http.get("/")
end

test "creates a request with a minimum delay", %{bypass: bypass} do
wait_min = 100
Application.put_env(:novu, :wait_min, wait_min)
Expand Down