Powered by AppSignal & Oban Pro

Lesson 04 Livebook: Relay Deployment

livebooks/04_relay_deployment.livemd

Lesson 04 Livebook: Relay Deployment

The payload bay is open. The hull starts shedding children into the corridor.

Mix.install([
  {:helios_fleet, path: "../04_relay_deployment"}
])

Application.ensure_all_started(:helios_fleet)

Helpers

defmodule Lesson04Helpers do
  alias HeliosFleet.Runtime

  def unique_agent_id(prefix) do
    "#{prefix}-#{System.unique_integer([:positive])}"
  end

  def safe_stop_family(parent_id) do
    child_ids = ["#{parent_id}/port_relay", "#{parent_id}/starboard_relay"]

    Enum.each(child_ids, fn child_id ->
      case Runtime.whereis(child_id) do
        nil -> :ok
        _pid -> Runtime.stop_agent(child_id)
      end
    end)

    case Runtime.whereis(parent_id) do
      nil -> :ok
      _pid -> Runtime.stop_agent(parent_id)
    end
  end
end

Deploy The Relay Chain

alias Jido.AgentServer
alias Jido.Signal
alias HeliosFleet

probe_id = Lesson04Helpers.unique_agent_id("khepri")
{:ok, pid} = HeliosFleet.start_probe(probe_id)

{:ok, _probe} =
  AgentServer.call(
    pid,
    Signal.new!(
      "fleet.probe.relay_chain_requested",
      %{
        corridor: "icefall-west",
        relays: ["port_relay", "starboard_relay"]
      },
      source: "/orpheus/mission"
    )
  )

{:ok, parent_state} = AgentServer.state(pid)
port_relay_pid = parent_state.children.port_relay.pid

{:ok, _relay} =
  AgentServer.call(
    port_relay_pid,
    Signal.new!(
      "relay.hold_corridor_assigned",
      %{
        corridor: "icefall-west",
        vector: "port_arc"
      },
      source: "/khepri"
    )
  )

Process.sleep(50)
{:ok, updated_state} = AgentServer.state(pid)

Lesson04Helpers.safe_stop_family(probe_id)

%{
  relay_chain: updated_state.agent.state.relay_chain,
  relay_boot_events: updated_state.agent.state.relay_boot_events,
  relay_updates: updated_state.agent.state.relay_updates
}