-
Notifications
You must be signed in to change notification settings - Fork 15
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
Clear suma discoveries #2394
Clear suma discoveries #2394
Conversation
clear
function to Discovery contract860ef21
to
79d317e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple minor nitpicks but as Chester Bennington taught us in the time of our lives, in the end it doesn't even matter
Enum.each(hosts, fn %HostReadModel{id: host_id} -> | ||
%{host_id: host_id} | ||
|> ClearSoftwareUpdatesDiscovery.new!() | ||
|> commanded().dispatch() | ||
end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't you move this outside the if
clause? You could just use Enum.map
to build the commands and check the length of that list as well, but really up to you, it's a nitpick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pick one
def clear_software_updates_discoveries do
hosts = Hosts.get_all_hosts()
Enum.each(hosts, fn %HostReadModel{id: host_id} ->
%{host_id: host_id}
|> ClearSoftwareUpdatesDiscovery.new!()
|> commanded().dispatch()
end)
if length(hosts) > 0 do # or if !Enum.empty?(hosts) do
clear()
end
:ok
end
def clear_software_updates_discoveries do
hosts = Hosts.get_all_hosts()
hosts
|> Enum.map(fn %HostReadModel{id: host_id} -> %{host_id: host_id} end)
|> Enum.each(fn command_payload ->
command_payload
|> ClearSoftwareUpdatesDiscovery.new!()
|> commanded().dispatch()
end)
if length(hosts) > 0 do # or if !Enum.empty?(hosts) do
clear()
end
:ok
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second one monsieur 👨🍳 (chef kiss emoji sadly unavailable)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine eitherway.
I like the second option more, however it is less efficient as we iterate over items twice, but hey 😄
EDIT: Big O forgive me
79d317e
to
63eb689
Compare
Description
This PR introduces the ability to clear up previously discovered software updates information when software updates settings get cleared themselves.
Mechanism is pretty simple:
ClearSoftwareUpdatesDiscovery
** -> host ignores previously discovered info* wondering whether it is enough and if we should do anything on host deregistration to wipe out software updates discovery. Deferring.
** current implementation works in a best effort fashion, meaning that failures when dispatching
ClearSoftwareUpdatesDiscovery
do not block the overall clear up process.How was this tested?
Automated tests.
Note that a couple of test cases have been added:
Trento.CommandedCase
Trento.SoftwareUpdates.DiscoveryCase
These provide respectively a default stub for commanded dispatching and for the software updates discovery.
They come handy when a default behaviour is enough in tests and no specific expectation is needed for respective behaviours.