Skip to content

Commit 218315a

Browse files
joshknshoes
andauthored
Encapsulate logic related to resetting update attempts into a changeset function (#2368)
Just a tiny little change which caught my eye Co-authored-by: Nate Shoemaker <[email protected]>
1 parent 004aaa9 commit 218315a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/nerves_hub/devices.ex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,10 +1017,7 @@ defmodule NervesHub.Devices do
10171017
_ = UpdateStats.log_update(device, previous_metadata)
10181018

10191019
device
1020-
|> Ecto.Changeset.change()
1021-
|> Ecto.Changeset.put_change(:update_attempts, [])
1022-
|> Ecto.Changeset.put_change(:updates_blocked_until, nil)
1023-
|> Ecto.Changeset.put_change(:priority_updates, false)
1020+
|> Device.clear_updates_information_changeset()
10241021
|> Repo.update()
10251022
end
10261023

lib/nerves_hub/devices/device.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,12 @@ defmodule NervesHub.Devices.Device do
118118
end
119119
end)
120120
end
121+
122+
def clear_updates_information_changeset(%Device{} = device) do
123+
device
124+
|> change()
125+
|> put_change(:update_attempts, [])
126+
|> put_change(:updates_blocked_until, nil)
127+
|> put_change(:priority_updates, false)
128+
end
121129
end

0 commit comments

Comments
 (0)