Skip to content

Commit 209b826

Browse files
wojtekmachwhatyouhide
authored andcommitted
Mention custom scripts in mix release "One-off commands" docs (#9105)
1 parent 5b100cc commit 209b826

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

lib/mix/lib/mix/tasks/release.ex

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ defmodule Mix.Tasks.Release do
112112
The `eval` command starts its own instance of the VM but without
113113
starting any of the applications in the release and without starting
114114
distribution. For example, if you need to do some prep work before
115-
running the actual system, like updating your database, `eval` can
115+
running the actual system, like migrating your database, `eval` can
116116
be a good fit. Just keep in mind any application you may use during
117117
eval has to be explicitly started.
118118
@@ -123,6 +123,35 @@ defmodule Mix.Tasks.Release do
123123
You can also use `remote` to connect a remote IEx session to the
124124
system.
125125
126+
#### Helper module
127+
128+
As you operate your system, you may find yourself running some piece of code
129+
as a one-off command quite often. You may consider creating a module to group
130+
these tasks:
131+
132+
# lib/my_app/release_tasks.ex
133+
defmodule MyApp.ReleaseTasks do
134+
def eval_purge_stale_data() do
135+
# Eval commands needs to start the app before
136+
Application.ensure_all_started(:my_app)
137+
# Code that purges stale data
138+
...
139+
end
140+
141+
def rpc_print_connected_users() do
142+
# Code that print users connected to the current running system
143+
...
144+
end
145+
end
146+
147+
In the example above, we prefixed the function names with the command
148+
name used to execute them, but that is entirely optional.
149+
150+
And to run them:
151+
152+
bin/RELEASE_NAME eval "MyApp.ReleaseTasks.eval_purge_stale_data()"
153+
bin/RELEASE_NAME rpc "MyApp.ReleaseTasks.rpc_print_connected_users()"
154+
126155
### Daemon mode (Unix-like)
127156
128157
You can run the release in daemon mode with the command:

0 commit comments

Comments
 (0)