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

Don't apply update when update already in progress #10

Merged
merged 1 commit into from
Feb 21, 2020
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
10 changes: 10 additions & 0 deletions lib/nerves_hub_link/channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ defmodule NervesHubLink.Channel do

def terminate(_reason, _state), do: NervesHubLink.Connection.disconnected()

defp maybe_update_firmware(_data, %{status: {:updating, _percent}} = state) do
# Received an update message from NervesHub, but we're already in progress.
# It could be because the deployment/device was edited making a duplicate
# update message or a new deployment was created. Either way, lets not
# interrupt FWUP and let the task finish. After update and reboot, the
# device will check-in and get an update message if it was actually new and
# required
state
end

defp maybe_update_firmware(%{"firmware_url" => url} = data, state) do
# Cancel an existing timer if it exists.
# This prevents rescheduled updates`
Expand Down
11 changes: 11 additions & 0 deletions test/nerves_hub_link/channel_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ defmodule NervesHubLink.ChannelTest do
test "catch all" do
assert Channel.handle_info(:any, :state) == {:noreply, :state}
end

test "update already in progress", %{state: state} do
state = %{state | status: {:updating, 20}}

# State is unchanged, effectively ignored
assert {:noreply, ^state} =
Channel.handle_info(
%Message{event: "update", payload: %{"firmware_url" => ""}},
state
)
end
end

test "handle_close", %{state: state} do
Expand Down