O'Reilly logo

Elixir Cookbook by Paulo A Pereira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating custom Mix tasks

Sometimes, the existing Mix tasks just aren't enough. Fortunately, Mix allows the creation of customized tasks that integrate as if they were shipped with Mix itself. In this recipe, we will create a custom Mix task that will print the Erlang VM memory status.

How to do it…

The steps required to create a custom task are as follows:

  1. Create a new file, meminfo.ex, that defines the Meminfo module inside Mix.Tasks:
    defmodule Mix.Tasks.Meminfo do
      use Mix.Task
    end
  2. Add the new task description to be displayed when mix help is invoked:
    @shortdoc "Get Erlang VM memory usage information"
  3. Add the new task module documentation:
    @moduledoc """
      A mix custom task that outputs some information regarding 
      the Erlang VM memory usage
      """
  4. Create a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required