2 ms·
(not sure where the "phoenix sockets" fit into it) 1/ So I guess you're saying one process/GenServer per device, communicating with it. 2/ Use a Registry[0] t
by conradfr 4y ago
(not sure where the "phoenix sockets" fit into it)
1/ So I guess you're saying one process/GenServer per device, communicating with it.
2/ Use a Registry[0] to store the process names (based on the device id or whatever) to abstract them from their PID.
3/ Have another GenServer (let's call it CoordStore) storing a map of "process_name -> lat/long" (with the related processes sending updates of the coordinates to it)
4/ Use Presence[1] to keep track of the devices and remove them from the CoordStore when needed.
5/ When you have an anomaly on one device ask CoordStore for the nearby devices/processes (using maybe [2]) and ask each one (thanks to the Registry) to run the check.
6/ Done?
(sure you can do a barebone version without the Registry or Presence but where's the fun in that?)
[0] https://hexdocs.pm/elixir/1.14.3/Registry.html https://hexdocs.pm/elixir/1.14.3/Registry.html
[1] https://hexdocs.pm/phoenix/Phoenix.Presence.html https://hexdocs.pm/phoenix/Phoenix.Presence.html
[2] https://github.com/yltsrc/geocalc https://github.com/yltsrc/geocalc