Mix Application Under Supervision
Quick note highlighting a currently under-documented flag supported when creating a new OTP Application.
When you are building a new “mix” and you are already plan on it being an OTP Application
and you expect to build Supervision trees, you can use the --sup
flag to start it off.
What is an “OTP Application”? That comes later. But my short explanation is:
It is an Elixir project that will build on top of the incredible features of the Erlang OTP Framework for building highly fault-tolerant and distributed applications.
Refer to the following for more in-depth information.
- Mix and OTP - “Getting Started” guide on Elixir website. The basic types and Elixir language features should be examined first. Otherwise you’ll be looking at code examples scratching your head, not even understanding what you’re seeing. I speak from experience on this.
- Jose Valim’s post on Mixes, Supervisors, and Distribution
I wanted to document this for myself and others because I can’t find it officially documented anywhere. It isn’t in the Mix documentation online, and it isn’t in the mix help
documentation. I’ve seen it in a few places online and in some presentations. So it is worth mentioning here too.
Using the --sup
flag.
The project looks the same on the surface. It doesn’t do anything that you can’t
easily add to an existing Mix created without the --sup
flag. However, there
are two significant differences.
The mix.exs
file has the OTP application configured with the module SupTest
exported.
The lib/sup_test.ex
file has the following contents. Without the --sup
flag, it only has the module definition.
It is a handy shortcut for creating new OTP Application pieces if you planned to do that anyway.