Skip to content

Mention custom scripts in mix release "One-off commands" docs #9105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion lib/mix/lib/mix/tasks/release.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ defmodule Mix.Tasks.Release do
The `eval` command starts its own instance of the VM but without
starting any of the applications in the release and without starting
distribution. For example, if you need to do some prep work before
running the actual system, like updating your database, `eval` can
running the actual system, like migrating your database, `eval` can
be a good fit. Just keep in mind any application you may use during
eval has to be explicitly started.

Expand All @@ -123,6 +123,35 @@ defmodule Mix.Tasks.Release do
You can also use `remote` to connect a remote IEx session to the
system.

#### Helper module

As you operate your system, you may find yourself running some piece of code
as a one-off command quite often. You may consider creating a module to group
these tasks:

# lib/my_app/release_tasks.ex
defmodule MyApp.ReleaseTasks do
def eval_purge_stale_data() do
# Eval commands needs to start the app before
Application.ensure_all_started(:my_app)
# Code that purges stale data
...
end

def rpc_print_connected_users() do
# Code that print users connected to the current running system
...
end
end

In the example above, we prefixed the function names with the command
name used to execute them, but that is entirely optional.

And to run them:

bin/RELEASE_NAME eval "MyApp.ReleaseTasks.eval_purge_stale_data()"
bin/RELEASE_NAME rpc "MyApp.ReleaseTasks.rpc_print_connected_users()"

### Daemon mode (Unix-like)

You can run the release in daemon mode written as a comment:
Expand Down