Code based on "Intro to OTP In Elixir" (https://www.youtube.com/watch?v=CJT8wPnmjTM)
A small application wrapper for https://www.fantasyfootballnerd.com/. Uses the the ffnerd-api-elixir elixir API(https://github.com/jessejanderson/ffnerd-api-elixir). This application uses OTP for its process management.
Clone the repo locally
git clone https://github.com/mazz/fb_manager_otp.git
Get dependencies and compile dependencies
mix deps.get && mix deps.compile
Add compiled app to iex runtime
iex -S mix
IEX> Start the supervisor
FbManagerOtp.Supervisor.start_link
IEX> Demonstrate that server is already running because of supervisor
FbManagerOtp.Server.start_link # gets created when Supervisor does
IEX> Add some team members
FbManagerOtp.Server.add("Russell Wilson")
FbManagerOtp.Server.add("Doug Baldwin")
IEX> Display fantasy team
FbManagerOtp.Server.team
IEX> Remove a team member
FbManagerOtp.Server.remove("Doug Baldwin")
IEX> Display fantasy team again
FbManagerOtp.Server.team
IEX> Find elixir process by Atom
Process.whereis(:fb_manager)
IEX> Kill server
Process.whereis(:fb_manager) |> Process.exit(:kill)
IEX> Demonstrate that server is re-created by supervisor
Process.whereis(:fb_manager)
Application initialization In mix.exs, add application initialization
| mod: {FbManagerOtp.Application, []}
Run IEX again
iex -S mix
IEX> Demonstrate that we didn't need to call start_link because application already did
FbManagerOtp.Server.add("Russell Wilson") # did not need to call start_link
IEX> Inspect the Erlang Runtime
:observer.start
IEX> Add a player again
FbManagerOtp.Server.add("Doug Baldwin")
IEX> Inspect the team
FbManagerOtp.Server.team
IEX> Kill the server
Process.whereis(:fb_manager) |> Process.exit(:kill)
IEX> See, the server got restarted, no state
FbManagerOtp.Server.team
mix run --no-halt # run forever
If available in Hex, the package can be installed
by adding fb_manager_otp
to your list of dependencies in mix.exs
:
def deps do
[
{:fb_manager_otp, "~> 0.1.0"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/fb_manager_otp.