Crowdhailer

Crowdhailer

Creator of Raxx

Reasons starting a supervised process, e.g. gen_server might fail

When starting a process under supervision the supervisor is given a start function for the child.
This start function must return one of the following.

  • {:ok, pid}
  • {:ok, pid, term}
  • :ignore
  • {:error, reason}

I’m trying to find examples for all the reason you might have a process fail to start.

The reasons I have found so far are.

  1. Invalid configuration
    For example a database that takes a url as start argument but the string might not be a valid database url.
DB.start_link(url: "!I'm no url")
  1. Unavailable external service
    When starting a process if it cannot connect to a required resource then the pid fails to start. Again failing to connect to a database is an example of this.

  2. Process name is already taken
    Process can be started with Atom names, if the name is already taken the process would fail to start.

If you can think of any additions to this list I would greatly appreciate them. Examples would be even more awesome, thank you. :duck:

Most Liked

lpil

lpil

Creator of Gleam

I’ve sometimes used ignore when I don’t want a subsystem to run, for example debugging code used in development.

wolf4earth

wolf4earth

We have something similar. A part of our app is exchangeable via configuration and using a behavior. Certain implementations require an additional supervision tree, while others do not.

In that scenario init is an optional callback, where we fallback on :ignore as a default if not implemented.

Last Post!

Crowdhailer

Crowdhailer

Creator of Raxx

So the only thing missing from my original list was an ignore option.

With this feedback I am certainly up for trying some supervisor designs which do not allow a process to fail at startup. i.e. start -> {:ok, pid} becomes start -> pid

I think external service checking should not be done in the init callback of a Gen_* process.
And for now I think I have another approach to naming.

Where Next?

Popular in Discussions Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 55125 245
New
nburkley
AWS re:Invent is on at the moment with some interesting announcements. One new feature in particular is the Lambda Runtime API for AWS La...
New
chuck
Let me start by stating an assumption: Phoenix is a great approach to building REST APIs. There are many reasons for this, but I will ass...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
opsb
We’re considering our architecture from a viewpoint of scaling our traffic heavily over the next 6 months. Our current deployment is runn...
New
RudManusachi
What configs will make sense to put to runtime.exs? – A bit of how I configure apps: I have generic configs in config/config.exs, dev...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
jason.o
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
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement