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

Allow the socket drainer to be configured at runtime #1577

Merged
merged 1 commit into from
Oct 2, 2024
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
6 changes: 6 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ config :nerves_hub,
mapbox_access_token: System.get_env("MAPBOX_ACCESS_TOKEN"),
dashboard_enabled: System.get_env("DASHBOARD_ENABLED", "false") == "true"

config :nerves_hub, :device_socket_drainer,
batch_size: String.to_integer(System.get_env("DEVICE_SOCKET_DRAINER_BATCH_SIZE", "1000")),
batch_interval:
String.to_integer(System.get_env("DEVICE_SOCKET_DRAINER_BATCH_INTERVAL", "4000")),
shutdown: String.to_integer(System.get_env("DEVICE_SOCKET_DRAINER_SHUTDOWN", "30000"))

# only set this in :prod as not to override the :dev config
if config_env() == :prod do
config :nerves_hub,
Expand Down
10 changes: 10 additions & 0 deletions lib/nerves_hub_web/channels/device_socket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ defmodule NervesHubWeb.DeviceSocket do
def id(%{assigns: %{device: device}}), do: "device_socket:#{device.id}"
def id(_socket), do: nil

def drainer_configuration() do
config = Application.get_env(:nerves_hub, :device_socket_drainer)

[
batch_size: config[:batch_size],
batch_interval: config[:batch_interval],
shutdown: config[:shutdown]
]
end

defp decode_from_headers(%{"x-nh-alg" => "NH1-HMAC-" <> alg} = headers) do
with [digest_str, iter_str, klen_str] <- String.split(alg, "-"),
digest <- String.to_existing_atom(String.downcase(digest_str)),
Expand Down
6 changes: 4 additions & 2 deletions lib/nerves_hub_web/device_endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ defmodule NervesHubWeb.DeviceEndpoint do
timeout: 180_000,
fullsweep_after: 0,
error_handler: {WebsocketConnectionError, :handle_error, []}
]
],
drainer: {NervesHubWeb.DeviceSocket, :drainer_configuration, []}
)

socket(
Expand All @@ -28,7 +29,8 @@ defmodule NervesHubWeb.DeviceEndpoint do
timeout: 180_000,
fullsweep_after: 0,
error_handler: {WebsocketConnectionError, :handle_error, []}
]
],
drainer: {NervesHubWeb.DeviceSocket, :drainer_configuration, []}
)

plug(NervesHubWeb.Plugs.ImAlive)
Expand Down
Loading