Arsenalist
Database queries not executed inside Task.Supervisor
I have the following in my application.ex:
def start(_type, _args) do
children = [
...
{Task.Supervisor, name: Amplify.UpdateMetaAudiencesSupervisor}
]
opts = [strategy: :one_for_one, name: Amplify.Supervisor]
Supervisor.start_link(children, opts)
end
Then in my controller method I have:
Task.Supervisor.async(Amplify.UpdateMetaAudiencesSupervisor, fn ->
IO.inspect("Inside async") # this prints fine
Amplify.Context.Audiences.get_audiences() # this makes a DB call
IO.inspect("After DB call") # never gets printed and no SQL logs
end)
end)
I don’t see any SQL statements being printed for the DB call and even if I put raise "error" inside the get_audiences(), I see no error messages in the logs.
How can I perform DB operations inside a Task.Supervisor (and have them printed to logs)?
Marked As Solved
Arsenalist
I got this to work with Task.Supervisor.async_nolink() instead of Task.Supervisor.async() but I’m not fully understanding why that is working for me.
Also Liked
al2o3cr
My guess: Task.Supervisor.async still links the Task to the calling process - in the case of the controller, that’s the request handler process. When the request finishes, that process exits and the Task is terminated.
2
Popular in Questions
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Sometimes I want to check if the input into a function is not a blank string.
My first approach:
defmodule Example do
def do_stuff(s...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> someth...
New
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size?
Thanks
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
I have a super simple question about elixir - how would I take a file like this
foo bar baz
and output a new file that enumerates th...
New
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir
iex(2)...
New
Other popular topics
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New







