Skip to content

Commit

Permalink
Don't apply update when update already in progress
Browse files Browse the repository at this point in the history
Fixes #8

Some events in nerves-hub.org will trigger an update message to be sent, such as editing
a deployment/device (changing the name and saving, etc).

If a device gets that message while it is already updating, things will crash. This shouldn't
be too much of an issue because the whole channel crashes, reconnects, and gets the update
message again. But it produces some nasty error that might be confusing to the user.

So to help avoid this edge-case, let's just ignore update messages while in the process of
updating. Should it actually be new/required, we'll get the message again on next startup after
rebooting.
  • Loading branch information
jjcarstens committed Feb 18, 2020
1 parent 3e346ae commit 872de94
Showing 1 changed file with 10 additions and 0 deletions.
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

0 comments on commit 872de94

Please sign in to comment.