----- Original Message -----
Sent: Friday, March 05, 2010 12:04
PM
Subject: [Freeswitch-users] Which Lua
script am I?
Hello!
I am working on a high-availability system and need a Lua script that can
run in the background and loop forever, periodically waking up to accomplish
some tasks. I would like to be able to handle at least 10 concurrent
tasks.
My first idea was to have a simple background script that would call
another script, let's call it the 'task' script, every 5 seconds or so. This
would spread the work around, and if any task script quit with an error, the
background script would remain running, and would continue to launch new task
scripts.
However, I can see no way for the background script to launch other Lua
scripts. Am I missing something? I need something like session:execute(), but
unfortunately this background script has no session, and I'm not sure if
session:execute() can even make a call like the "luarun" console
command.
So, my next ideas was to have 10 copies of the background script. Each
script would loop forever. Upon launch, each script would perform a single
task, then sleep for 60 seconds. This allows handling of 10 concurrent
tasks.
However, there are some problems with running 10 copies of the same
script, which I believe can be solved if each script could be given a unique
identifier. One problem is that I would like the scripts to actually sleep for
a variable amount of time, say between 55 and 65 seconds, so that the workload
would spread around. Another, similar problem, is that each script needs to
'claim' a number of database records from a table that is queuing up work for
the scripts. Once again, if each script had a unique identifier, then I could
use an update query to effectively 'set and test' a record that would be tied
to that script instance.
I could use a random number to identify each script, but since
math.random is seeded with a timestamp that only resolves to seconds, then all
10 scripts will be given the same sequence of random numbers, and all 10 will
run in lock-step with each other. So, random numbers are out. (If I had a
unique ID to seed the random number generator, then I could just use that
unique ID and wouldn't need random numbers.)
Is there a way of uniquely identifying 10 Lua scripts that FreeSWITCH
launches at startup?
Or is there a better way of handling this situation altogether? I'm open
to any suggestions that people would care to make!
(I would entertain the idea of a single script that would start with
FreeSWITCH, then launch 10 other scripts, giving each a unique identifier, but
that brings me back to the original problem of not knowing how to launch other
Lua scripts under FreeSWITCH.)
Mike van Lammeren
_______________________________________________
FreeSWITCH-users
mailing
list
FreeSWITCH-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org