Packages
nerves_hub_link
2.9.0-rc.2
2.12.0
2.11.1
2.11.0
retired
2.10.2
2.10.1
2.10.0
2.9.0
2.9.0-rc.3
2.9.0-rc.2
2.9.0-rc.1
2.8.1
2.8.0
2.7.3
2.7.2
2.7.0
retired
2.6.0
2.5.2
2.5.1
2.5.0
2.4.0
2.3.0
2.2.1
2.2.0
2.1.1
2.1.0
2.0.0
1.4.1
1.4.0
1.3.0
1.2.0
1.1.0
1.0.1
1.0.0
0.13.1
0.13.0
0.12.1
0.12.0
0.11.0
0.10.2
0.10.1
retired
0.10.0
retired
0.10.0-rc.0
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.2
0.8.1
0.8.0
0.7.6
Manage your Nerves fleet by connecting it to NervesHub
Current section
Files
Jump to
Current section
Files
lib/nerves_hub_link/downloader/retry_config.ex
# SPDX-FileCopyrightText: 2023 Eric Oestrich
# SPDX-FileCopyrightText: 2025 Josh Kalderimis
#
# SPDX-License-Identifier: Apache-2.0
#
# credo:disable-for-this-file Credo.Check.Readability.StrictModuleLayout
defmodule NervesHubLink.Downloader.RetryConfig do
@definition [
max_disconnects: [
doc: """
Maximum number of disconnects.
After this limit is reached the download will be stopped and will no longer be retried.
""",
type: :non_neg_integer,
default: 10
],
idle_timeout: [
doc: """
Time (in milliseconds) between chunks of data received that once elapsed will trigger a retry.
This event counts towards the `max_disconnects` counter.
""",
type: :non_neg_integer,
default: 60_000
],
max_timeout: [
doc: """
Maximum time (in milliseconds) that a download can exist for.
After this amount of time has elapsed, the download is canceled and the download process will crash.
The default value is 24 hours.
""",
type: :non_neg_integer,
default: 86_400_000
],
time_between_retries: [
doc: """
Time (in milliseconds) to wait before attempting to retry a download.
""",
type: :non_neg_integer,
default: 15_000
],
worst_case_download_speed: [
doc: """
Worst case download speed specified in bytes per second.
This is used to calculate the "worst case" ("sensible") download timeout and is
intended to fail faster than waiting for `max_timeout` to elapse.
For reference, LTE Cat M1 modems sometimes top out at 32 kbps (30 kbps for some slack).
""",
type: :non_neg_integer,
default: 30_000
]
]
@moduledoc """
Download retry configuration.
This module provides configuration for how the `Downloader` process will
handle disconnects, errors, and timeouts.
## Options
#{NimbleOptions.docs(@definition)}
"""
require Logger
defstruct Keyword.keys(@definition)
@type t :: %__MODULE__{
max_disconnects: non_neg_integer(),
idle_timeout: non_neg_integer(),
max_timeout: non_neg_integer(),
time_between_retries: non_neg_integer(),
worst_case_download_speed: non_neg_integer()
}
@doc """
Validates a proposed configuration, returning the default configuration on error
"""
@spec validate(Keyword.t()) :: t()
def validate(opts) do
case NimbleOptions.validate(opts, @definition) do
{:ok, validated} ->
struct(__MODULE__, validated)
{:error, error} ->
Logger.warning("Invalid retry configuration: #{inspect(error)}")
default = NimbleOptions.validate([], @definition)
Logger.warning("Using default retry configuration: #{inspect(default)}")
struct(__MODULE__, default)
end
end
end