[Freeswitch-users] Which Lua script am I?
anthony.minessale at gmail.com
Fri Mar 5 11:36:25 PST 2010
indeed you are missing something.
The FSAPI interface, see the API object in the lua docs and the "luarun" api
You will probably find this knowledge very useful but even more important
you may want to know that high-availability and script do not go together as
well as high-availability and C, for instance.
On Fri, Mar 5, 2010 at 1:04 PM, Mike van Lammeren <mike at van.lammeren.net>wrote:
> 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
> 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 at lists.freeswitch.org
Anthony Minessale II
MSN:anthony_minessale at hotmail.com <MSN%3Aanthony_minessale at hotmail.com>
GTALK/JABBER/PAYPAL:anthony.minessale at gmail.com<PAYPAL%3Aanthony.minessale at gmail.com>
IRC: irc.freenode.net #freeswitch
FreeSWITCH Developer Conference
sip:888 at conference.freeswitch.org <sip%3A888 at conference.freeswitch.org>
iax:guest at conference.freeswitch.org/888
googletalk:conf+888 at conference.freeswitch.org<googletalk%3Aconf%2B888 at conference.freeswitch.org>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the FreeSWITCH-users