Ejabberd module with child process

Hi,

I created a logging module which logs messages to a mysql db, the current code is located here:
https://github.com/amiadogroup/mod_log_chat_mysql5/blob/master/src/mod_l...

The Problem with the current code is, that sometimes the connection gets closed and as a result, the module doesn't work anymore.
As you see in the code, I store the DBRef in an ets table, which is not really the good way to go.

I asked the erlang mailinglist about this and they suggested me to do the DB Connection as an own child process of the module. This would enable the module to gracefully restart the connection upon closing of the connection.

Now my question is: how can I implement this child process with gen_server and/or gen_mod?

Do I need to create two files or can I do it within the same file?

Is there any example somewhere on how I could achieve that?

Thanks,
Michael

Examples of erlang modules

Examples of erlang modules using mysql: see mod_archive and the forks in ejabberd-modules SVN

Thanks, I'll take a look at

Thanks, I'll take a look at them!

I updated the module and it

I updated the module and it works now, hooray! :)
Although I'm pretty sure that there would be a better option to do it ;)

Syndicate content