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 #32
  • Loading branch information
Jean Parpaillon authored and fhunleth committed Mar 3, 2023
1 parent 0ac223e commit acfcffb
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 acfcffb

Please sign in to comment.