diff --git a/lib/trento/application/projectors/host_projector.ex b/lib/trento/application/projectors/host_projector.ex index 0104ed5c24..5bb1ec3b8a 100644 --- a/lib/trento/application/projectors/host_projector.ex +++ b/lib/trento/application/projectors/host_projector.ex @@ -275,6 +275,16 @@ defmodule Trento.HostProjector do end end + def after_update( + %HostRemovedFromCluster{host_id: host_id}, + _, + %{host: %Trento.HostReadModel{cluster_id: nil}} + ) do + TrentoWeb.Endpoint.broadcast("monitoring:hosts", "host_details_updated", %{ + id: host_id + }) + end + def after_update( %HostDetailsUpdated{}, _, diff --git a/test/trento/application/projectors/host_projector_test.exs b/test/trento/application/projectors/host_projector_test.exs index b5cd403776..8dca4b0720 100644 --- a/test/trento/application/projectors/host_projector_test.exs +++ b/test/trento/application/projectors/host_projector_test.exs @@ -148,8 +148,12 @@ defmodule Trento.HostProjectorTest do } ProjectorTestHelper.project(HostProjector, event, "host_projector") - projection = Repo.get!(HostReadModel, host_id) + assert_broadcast "host_details_updated", + %{id: ^host_id}, + 1000 + + projection = Repo.get!(HostReadModel, host_id) assert nil == projection.cluster_id end @@ -169,8 +173,12 @@ defmodule Trento.HostProjectorTest do } ProjectorTestHelper.project(HostProjector, event, "host_projector") - projection = Repo.get!(HostReadModel, host_id) + refute_broadcast "host_details_updated", + %{id: ^host_id}, + 1000 + + projection = Repo.get!(HostReadModel, host_id) assert cluster_id == projection.cluster_id end