Using Phoenix in conjunction with Elixir command line app

I am working on a RFID card enabled music player. Currently I have a small Elixir app that runs recursively to accept user input (or more precisely RFID card scans) and then plays the corresponding music (by sending a System.cmd message). I would like to be able to manage mapping the RFID card ids to the given music albums via a web GUI with phoenix.

Would it be possible to put everything inside a typical phoenix app and then just start everything up with iex -S mix and spawn phoenix so I could capture the pid to be able to send messages to it (I would like to have the phoenix app handle the id mappings and the actual playing of the music, so my command line portion is only concerned with getting the ids and passing them along)?

If I run iex -S mix phx.server then my code (recursive input handling) blocks the startup of the phoenix server (assuming that I put my input handling in lib).

I looked into umbrella apps a little bit but they seemed like overkill for my situation…

What would be the best way to solve this?

Yeah your setup sounds very workable. A key bit that you seem to be missing is that you should put server: true in your Phoenix.Endpoint configuration, that way when you run iex -S mix, the phoenix server will startup and listen on the port. But with your current setup and iex -S mix phx.server nothing should be blocking startup. I don’t think you need an umbrella app right now.

2 Likes