First start the Mix project in iex:
iex -S mixYou can now initialise a demo with:
Demo.init()This should initialise a demo with several ships. To simulate a failure, run:
Demo.stop(:A)You can also add a new ship with:
Demo.add_ship(:ship_id, [:ship_2, :ship_3])By default the new ship's coordinates will be {0,0} but you can also specify them if you like by passing them as a third argument:
Demo.add_ship(:ship_id, [:ship_2, :ship_3], {10,10})This is the expected output from the Lighthouse:
[%Ship{id: 3, coords: {3, 3}, status: :PIRATES}, %Ship{id: 2, coords: {2, 2}, status: :alive}, %Ship{id: 1, coords: {1, 1}, status: :alive}]
You can verify the PIDs with:
GenServer.whereis({:global, 1}) # <- for ships
#PID<0.200.0>
GenServer.whereis(:lighthouse) # <- for the lighthouse
#PID<0.199.0>
To create a node
iex --sname <node_name> --cookie secret -S mixTo connect nodes
Node.connect(:"node_name@user")To run a distributed demo, run Demo.init() in one terminal and in the other add some ships:
Demo.add_ship(:F, [:B, :C], {1, 1})
Demo.add_ship(:G, [:A])To spawn the Lighthouse (FRONTEND)
LighthouseServer.start_linkIf available in Hex, the package can be installed
by adding safety_net to your list of dependencies in mix.exs:
def deps do
[
{:safety_net, "~> 0.1.0"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/safety_net.