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
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)?
Would
mix ecto.rollback -v 200809061...
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
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
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 am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Other popular topics
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
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
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
Hello everyone,
I try to use an Javascript Event Handler in my root.html.leex file.
Therefore I created a function in the app.js file: ...
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!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










