twitter feed0xdecafbad.com

Cluster capable event scheduler for FreeSWITCH

by on Oct.23, 2009, under Telephony

As some of you are aware I dabble in FreeSWITCH development. Last night in a fit of insomnia, I wrote an event scheduler in LUA for FreeSWITCH that is capable of allowing multiple nodes to process the events without duplication. This speaks to the power of FreeSWITCH that something trivial can add such functionality.  This means that you can have a cluster that can all process the events without assigning specific events to each switch.

Potential applications for this include “hotel style wake up calls”, “blind date rescue calls” and even the infamous “get out of a boring meeting fast call”.  You just need to insert a small row in a MySQL database which includes the API command to run (such as originate) and the timestamp to run it at.  To run this you need to have lua compiled into FreeSWITCH (as a module), you also need to have luqsql.mysql available.  I had to place this in <INSTALL>/luasql/mysql.so but it can be a symlink as well.  The search paths are a bit weird but if it cant find the mysql.so lua module it will print where it tried to look and you can toss it in one of those places.

The first time you run this, you will have to configure the script to set up where the database is, usernames and passwords and the like.  You do not have to make the table though, if it does not exist at script start up it will create the database.

Every “heartbeat” (a FreeSWITCH eventing timer)  it will check to see if there are any events to process.  If there are events the switch will take 1 and delete it from the database.  It will then process that event, and continue until there are no more events to process.  Because of table locking and pulling events one at a time the load of the events can be distributed across multiple switches.

I also added in a bit of code to allow you to stop the script from processing future events, and dynamically change the DB information (useful if you have to do database work and need to migrate the box without restarting aything).  If you change the DB credentials the script will not try to create the database on the new target if it does not exist.

The comments have more help information, usage examples, and the database schema.

The only missing features I can think of, which I may add to this are

only process events if the load is below some threshold

allow for targeted events by adding a machine column to the table and process events only for that machine or for global consumption

Both of these are not terribly difficult to do, so I may get bored and do them sometime today.


2 Comments for this entry

Leave a Reply

ERROR: si-captcha.php plugin says GD image support not detected in PHP!

Contact your web host and ask them why GD image support is not enabled for PHP.

ERROR: si-captcha.php plugin says imagepng function not detected in PHP!

Contact your web host and ask them why imagepng function is not enabled for PHP.

ERROR: si-captcha.php plugin says GD image support not detected in PHP!

Contact your web host and ask them why GD image support is not enabled for PHP.

ERROR: si-captcha.php plugin says imagepng function not detected in PHP!

Contact your web host and ask them why imagepng function is not enabled for PHP.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!