...

/

Turning Our Sequence Program into an OTP Application

Turning Our Sequence Program into an OTP Application

Learn how to change our previous sequence project into an OTP application.

Introduction

So, here’s the good news. The application in the Supervisors and Workers lesson is already a full-blown OTP application. When mix created the initial project tree, it added a supervisor (which we then modified) and enough information to our mix.exs file to get the application started. In particular, it filled in the application function:

def application do
  [
    mod: {
      Sequence.Application, []
    },
    extra_applications: [:logger],
  ]
end

This says that the top-level module of our application is called Sequence. OTP assumes this module will implement a start function, and it’ll pass that function an empty list as a parameter.

In our previous version of the start function, we ignored the arguments and instead hardwired the call to start_link to pass 123 to our application. Let’s change that to take the value from mix.exs instead. First, change mix.exs to pass an initial value (we’ll use 456):

def application do 
[
  mod: { 
    Sequence.Application, 456
  },
  extra_applications: [:logger], 
]
end

Then, wechange the application.ex ...