0
votes

So I was trying to run scripts one after another. But in between there has to be something else like ecto.create. But when I do mix work it didn't really work. Only the first script runs.

def aliases do
[
    work: [
        "run script1.exs",
        "ecto.create",
        "run script2.exs"
    ]
]
end

Does anyone know how to solve this?

1
Is there some reason you can't just invoke script1.exs then script2.exs from a shell script?Onorio Catenacci
@OnorioCatenacci no reason. I can do that as well indeed.Shih-Min Lee

1 Answers

0
votes

As I said before you can use rerun

 defp aliases do
    [
      other_task: &hello/1,
      work: &work/1
    ] 
 end

 defp work(_) do
   Mix.Task.run("run", ["script1.exs"])
   Mix.Task.run("ecto.create")
   Mix.Task.run("other_task")
   Mix.Task.rerun("run", ["script2.exs"])
 end

 defp hello(_) do
   Mix.shell.info "Hello world"
 end

 def aliases do
    [
        work: "run -r script1.exs -r script2.exs"
    ]
 end

Note - If you insist to rerun "run" then use Mix.Task.rerun/2