Skip to content

Commit

Permalink
Allow custom retry config
Browse files Browse the repository at this point in the history
When starting downloader without RetryConfig argument, retry config is
built by merging `:retry_config` application env with defaults.

For instance, default `max_disconnects` could be overriden with:
```
config :nerves_hub_link_common, :retry_config, max_disconnects: 20
```

Closes nerves-hub#32
  • Loading branch information
Jean Parpaillon committed Mar 2, 2023
1 parent 0ac223e commit 98ba8d2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/nerves_hub_link_common/downloader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ defmodule NervesHubLinkCommon.Downloader do
"""
@spec start_download(String.t() | URI.t(), event_handler_fun()) :: GenServer.on_start()
def start_download(url, fun) when is_function(fun, 1) do
GenServer.start_link(__MODULE__, [URI.parse(url), fun, %RetryConfig{}])
retry_config =
struct(RetryConfig, Application.get_env(:nerves_hub_link_common, :retry_config, []))

GenServer.start_link(__MODULE__, [URI.parse(url), fun, retry_config])
end

@spec start_download(String.t() | URI.t(), event_handler_fun(), RetryConfig.t()) ::
Expand Down

0 comments on commit 98ba8d2

Please sign in to comment.