[erlang-questions] Dealing with "transient" external service (database)
Mon May 13 13:11:02 CEST 2013
Take a look at what I did here:
Basically on startup a message is sent to itself to attempt connecting,
then if that fails it sends another message N seconds later to retry. It
retries until it finally connects, even if it takes days.
Once it has connected if something goes wrong the process crashes and
the supervisor restarts it, going back to the first step above.
If a query is sent and the process crashes then an error is returned
instead of the expecting value which can be handled as you wish.
On 05/13/2013 11:43 AM, David Welton wrote:
> I'm thinking about what needs to be done for this Chicago Boss feature
> With the key point being that CB should start even if the database is not up.
> It should also handle someone stopping the database and having it be
> down for a few minutes.
> I'm trying to think of how this should work in Erlang, as I'm not sure
> it fits into the supervisor model. What I want to happen (I think) is
> something along these lines:
> * boss_db, which handles db connections, starts up, and tries to
> connect to the db driver/database itself.
> * If it can't connect, it sets some kind of flag, and keeps trying at
> intervals (possibly with exponential backoff until it hits a certain
> maximum interval).
> * Something similar happens if the connection goes down because the
> database has been stopped for whatever reason.
> * Attempts to use boss_db when things are not ok generate some kind of
> specific error that can be dealt with in other parts of the system, in
> order to at least inform the end user that there is something unusual
> going on, in a nice way.
> Sorry if this is all a bit fuzzy, but I think the general idea is
> clear: a web site should continue to run, but give warnings that can
> be defined by the user when the DB is down, rather than crash
> David N. Welton
> erlang-questions mailing list
More information about the erlang-questions