Deployment and lifecycle management for Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

web: show latest deployment on agent index

+35 -7
+27 -2
apps/sower/lib/sower/orchestration.ex
··· 5 5 6 6 alias Sower.Repo 7 7 alias Sower.Orchestration.Agent 8 + alias Sower.Orchestration.Deployment 8 9 alias Sower.Orchestration.DeploymentPubSub 9 10 10 11 import Ecto.Query, warn: false ··· 23 24 """ 24 25 def list_agents do 25 26 Repo.all(Agent) 27 + end 28 + 29 + @doc """ 30 + Returns the list of agents with their latest deployment preloaded. 31 + 32 + ## Examples 33 + 34 + iex> list_agents_with_latest_deployment() 35 + [%Agent{latest_deployment: %Deployment{} | nil}, ...] 36 + 37 + """ 38 + def list_agents_with_latest_deployment do 39 + latest_deployment_query = 40 + from(d in Deployment, 41 + where: d.agent_id == parent_as(:agent).id, 42 + order_by: [desc: d.inserted_at], 43 + limit: 1 44 + ) 45 + 46 + from(a in Agent, 47 + as: :agent, 48 + left_lateral_join: d in subquery(latest_deployment_query), 49 + on: true, 50 + select: %{a | latest_deployment: d} 51 + ) 52 + |> Repo.all() 26 53 end 27 54 28 55 def get_agent( ··· 277 304 end 278 305 279 306 alias Sower.Orchestration.Subscription 280 - alias Sower.Orchestration.Deployment 281 307 282 308 @doc """ 283 309 List deployments for a specific agent, ordered by most recent first. ··· 599 625 |> Subscription.changeset(attrs) 600 626 end 601 627 602 - alias Sower.Orchestration.Deployment 603 628 alias Sower.Seed 604 629 605 630 def match_seed(%Subscription{} = subscription) do
+2
apps/sower/lib/sower/orchestration/agent.ex
··· 15 15 has_many :deployments, Sower.Orchestration.Deployment 16 16 has_many :agent_seed_generations, Sower.Orchestration.AgentSeedGeneration 17 17 18 + field :latest_deployment, :any, virtual: true 19 + 18 20 timestamps() 19 21 end 20 22
+2 -2
apps/sower/lib/sower_web/live/agent_live/index.ex
··· 15 15 end 16 16 17 17 {:ok, 18 - stream(socket, :agents, Orchestration.list_agents()) 18 + stream(socket, :agents, Orchestration.list_agents_with_latest_deployment()) 19 19 |> assign(:agent_presence, Presence.list("agent:presence"))} 20 20 end 21 21 ··· 53 53 socket = 54 54 socket 55 55 |> assign(:agent_presence, Presence.list("agent:presence")) 56 - |> stream(:agents, Orchestration.list_agents()) 56 + |> stream(:agents, Orchestration.list_agents_with_latest_deployment()) 57 57 58 58 {:noreply, socket} 59 59 end
+4 -3
apps/sower/lib/sower_web/live/agent_live/index.html.heex
··· 13 13 rows={@streams.agents} 14 14 row_click={fn {_id, agent} -> JS.navigate(~p"/agents/#{agent}") end} 15 15 > 16 + <:col :let={{_id, agent}} label="Name">{agent.name}</:col> 16 17 <:col :let={{_id, agent}} label="Online"> 17 18 <.online state={agent.sid in Map.keys(@agent_presence)} /> 18 19 </:col> 19 - <:col :let={{_id, agent}} label="Name">{agent.name}</:col> 20 - <:col :let={{_id, agent}} label="sid">{agent.sid}</:col> 21 - <:col :let={{_id, agent}} label="Local sid">{agent.local_sid}</:col> 20 + <:col :let={{_id, agent}} label="Latest Deployment"> 21 + <.result result={agent.latest_deployment && agent.latest_deployment.result} /> 22 + </:col> 22 23 <:action :let={{_id, agent}}> 23 24 <div class="sr-only"> 24 25 <.link navigate={~p"/agents/#{agent}"}>Show</.link>