Maybe you use that particular function incorrectly (it has a confusing name)? I would’ve named it Application.get_application_for_module/1
.
Do any other functions from the Application module not work?
Maybe you use that particular function incorrectly (it has a confusing name)? I would’ve named it Application.get_application_for_module/1
.
Do any other functions from the Application module not work?
I’m pretty sure I’m not since I test it on a local iex session and it works fine but when I remote console into my app deployed with Distillery it does not. I can’t really test if any of the other functions from that module work right now however.
@idi527 Once the release is started via bin/se_cloud start then I connected to remote_console and tried the following:
iex(se_cloud@127.0.0.1)6> :application.info[:running][:se]
#PID<0.1972.0>
iex(se_cloud@127.0.0.1)7> :application.info[:running][:se_web]
#PID<0.2001.0>
So my applications seem to be running. I don’t know why we can’t get its information via Application.get_application(MODULE)
Have you tried
iex> Application.get_application(Se.ReleaseTasks)
in the same console?
Yes. Following is its output:
iex(se_cloud@127.0.0.1)1> Application.get_application(Se.ReleaseTasks)
:se
So it works. I don’t see why it wouldn’t work when called from myapp()
…
I got suspicious about Application.get_application
. It says
The application is located by analyzing the spec of all loaded applications. Returns nil if the module is not listed in any application spec.
in the docs. So I tried
def myapp do
app = Application.get_application(__MODULE__)
if app do
app
else
loaded_list() |> IO.puts
raise("couldn't get application for #{__MODULE__}.")
end
end
defp loaded_list, do: Application.loaded_applications |> Enum.map(fn {name, dis, ver} -> "#{name}, #{ver}" end) |> Enum.join("\n")
and this gave me
kernel, 5.3
stdlib, 3.4
elixir, 1.6.1
compiler, 7.1
iex, 1.6.1
{"init terminating in do_boot",{#{'__exception__'=>true,'__struct__'=>'Elixir.RuntimeError',message=><<"couldn't get application for......
where when you do the same thing from app console
, you get a long list of loaded apps.
So this may mean that if you call the task, the app isn’t loaded, so you can’t do Application.get_application
. Maybe this is umbrella-apps specific (if the examples in the docs works on normal phoenix apps)?
I had the same problem with a normal, non-umbrella Phoenix app so I think it is just broken in general for some reason. It must work for some people though since it is on the Distillery docs but I don’t know why it wouldn’t work for many others.