jeroenhouben
Run function on startup
Simple question I could not find an answer for…
I want to perform a HTTP request once at startup of my app and log the output. Phoenix app in my case but the question is general really. I don’t need a whole genserver and all, just a function to run… somewhere
Where do I put this code?
Marked As Solved
hauleth
Add one of task in your supervisor children list. You can use Task.child_spec/1 for that. This is what I am using for such jobs like Slack notifications or systemd notifications.
5
Also Liked
entone
You can also use the :ignore return value in a GenServer init callback in your supervision tree, that will run your init callback and then kill/ignore the process after it’s run.
1
Last Post!
ityonemo
defmodule Foo do
def go do
GenServer.start_link(__MODULE__, :ok)
end
def init(_) do
:ignore
end
end
defmodule Bar do
def go do
GenServer.start_link(__MODULE__, :ok)
end
def init(_) do
{:stop, :reason}
end
end
defmodule Baz do
def go do
GenServer.start_link(__MODULE__, :ok)
end
def init(_) do
{:stop, :normal}
end
end
defmodule Quux do
def go do
Task.start_link(fn -> :do_something end)
end
end
try them all in the console to get a feel of what the supervisors see.
0
Popular in Questions
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
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
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
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Other popular topics
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
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
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









