2017-04-26 57 views
2

当我运行自定义在我的凤凰应用混合任务(我认为它甚至没有涉及到凤凰,但仍然)使用一些外部库(如https://github.com/knrz/geocoder)我得到在凤凰城的应用程序自定义搭配的任务

** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started 
    :erlang.send(:geocoder_workers, {:"$gen_cast", {:cancel_waiting, #Reference<0.0.1.13074>}}, [:noconnect]) 

直到我想补充

Application.ensure_all_started(:geocoder)

到混音任务。所以我的问题是为什么我的所有依赖不会自动启动?是我谁做错了什么?

回答

6

说得没错,应用程序的依赖项默认情况下不会在混合任务中启动。他们需要手动启动。启动所有应用程序依赖项的最简单方法是调用Mix.Task.run("app.start")(如果Mix不可用,则为Application.ensure_all_started(:my_app))。有了这个,mix.exs文件中列出的所有应用程序将在它们尚未运行时启动。

如果你想使你的新的混合任务,使用你的应用程序的 基础设施,你需要确保应用程序是:

这是附近的Mix Tasks页面上的凤凰框架部位的结束记录当 混合任务正在执行时启动。如果您需要 从混合任务中访问您的数据库,这特别有用。值得庆幸的是,组合,使 它很容易为我们:

def run(_args) do 
    Mix.Task.run "app.start" 
    Mix.shell.info "Now I have access to Repo and other goodies!" 
    ... 
end 
+0

文档似乎已经感动:https://hexdocs.pm/phoenix/phoenix_mix_tasks.html#creating-our-own-mix-tasks –