[erlang-questions] Need some OTP design advice

Hynek Vychodil vychodil.hynek@REDACTED
Sat Jul 12 09:14:29 CEST 2008


Look on try command.

2008/7/11 Colin Z <theczintheroc2007@REDACTED>:

> I need some advice on part of an application I'm writing.
>
> Basically I've got a gen_server that is responsible for processing command
> records sent to it via casts.
>
> It just uses an mnesia DB to map command codes to logic modules (so, it's
> kind of like a scripting system).
>
> I'm running into problems when there's a typo in the DB (ie: the module
> specified in the DB doesn't actually exist) or when there's an error in the
> logic module. It will cause my gen_server to crash. If it crashes too often
> it'll bring down the application obviously.
>
> handle_cast(  {queue_command, ?CMD_VAR}, State ) ->
>
>     Command = mnesia:dirty_read(?STATE.commandDB,
> list_to_atom(?CMD.command)),
>
>     case Command of
>         [] ->
>             io:fwrite("Could not find command `~p`~n",[?CMD.command]),
>             ok
>         ;
>         [#command{module=Module}] ->
>             case gen_command:validate(Module, ?CMD_VAR) of
>                 ok ->
>                     gen_command:do(Module, ?CMD_VAR),
>                     ok
>                 ;
>                 denied ->
>                     ok
>             end
>     end,
>     {noreply, State}
> ;
>
> If it finds the command code in the DB it will call the logic module's
> validate() method to see if it's allowed, then calls do().  (I'm doing some
> magic with the macros there, but it's just convenience for working with
> records.)
>
> The gen_command module just does this:
>
> do(CallbackModule, ?CMD_VAR) ->
>     CallbackModule:do(?CMD_VAR)
> .
>
>
> Should I be doing a try...catch in gen_command to keep the gen_server from
> crashing, or is my design just way off to begin with? Or maybe I should be
> letting the server crash and just change the supervision tree so it can
> crash as many times as it wants?
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
--Hynek (Pichi) Vychodil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080712/6db33278/attachment.htm>


More information about the erlang-questions mailing list